tests: fix zombie consul process while invoking TestServer.Stop() method in sdk/testutil in Windows (#6032)

* Fix zombie consul process in Windows 

Windows doesn't support Interrupt signal, thus while stop it on Windows platform
it would fail and left zombie consul process
This commit is contained in:
Song Yihan 2020-01-23 00:34:35 +08:00 committed by Hans Hasselberg
parent 7b17f789d3
commit 04305be555

View File

@ -26,6 +26,7 @@ import (
"strings"
"testing"
"time"
"runtime"
"github.com/hashicorp/consul/sdk/freeport"
"github.com/hashicorp/consul/sdk/testutil/retry"
@ -350,8 +351,14 @@ func (s *TestServer) Stop() error {
}
if s.cmd.Process != nil {
if err := s.cmd.Process.Signal(os.Interrupt); err != nil {
return errors.Wrap(err, "failed to kill consul server")
if runtime.GOOS == "windows" {
if err := s.cmd.Process.Kill(); err != nil {
return errors.Wrap(err, "failed to kill consul server")
}
} else { // interrupt is not supported in windows
if err := s.cmd.Process.Signal(os.Interrupt); err != nil {
return errors.Wrap(err, "failed to kill consul server")
}
}
}