Make testutil.TestServer work correctly on Windows.

This commit is contained in:
kaskavalci 2016-04-15 15:35:45 +03:00
parent 5d0d61349e
commit 556f20b8c3

View File

@ -127,7 +127,7 @@ type TestKVResponse struct {
// TestServer is the main server wrapper struct.
type TestServer struct {
PID int
cmd *exec.Cmd
Config *TestServerConfig
t TestingT
@ -215,7 +215,7 @@ func NewTestServerConfig(t TestingT, cb ServerConfigCallback) *TestServer {
server := &TestServer{
Config: consulConfig,
PID: cmd.Process.Pid,
cmd: cmd,
t: t,
HTTPAddr: httpAddr,
@ -240,10 +240,13 @@ func NewTestServerConfig(t TestingT, cb ServerConfigCallback) *TestServer {
func (s *TestServer) Stop() {
defer os.RemoveAll(s.Config.DataDir)
cmd := exec.Command("kill", "-9", fmt.Sprintf("%d", s.PID))
if err := cmd.Run(); err != nil {
if err := s.cmd.Process.Kill(); err != nil {
s.t.Errorf("err: %s", err)
}
// wait for the process to exit to be sure that the data dir can be
// deleted on all platforms.
s.cmd.Wait()
}
// waitForAPI waits for only the agent HTTP endpoint to start