diff --git a/testutil/server.go b/testutil/server.go index c0d9bc4fa9..5574f668ce 100644 --- a/testutil/server.go +++ b/testutil/server.go @@ -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