Skip to content

Commit

Permalink
Make testutil.TestServer work correctly on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaskavalci committed Apr 15, 2016
1 parent 5d0d613 commit 556f20b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions testutil/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 556f20b

Please sign in to comment.