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 013dfe109f
commit 88dc6121d8
1 changed files with 9 additions and 2 deletions

View File

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