From bb4ab7e33351d304fc7a8ef24186066f2b7cfac3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 24 Sep 2015 23:37:01 +0900 Subject: [PATCH] integration: Robust process termination --- integration-tests/server_tester.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/integration-tests/server_tester.go b/integration-tests/server_tester.go index 9f41e620..8b6c4faa 100644 --- a/integration-tests/server_tester.go +++ b/integration-tests/server_tester.go @@ -21,6 +21,7 @@ import ( "sort" "strconv" "strings" + "syscall" "testing" "time" ) @@ -203,10 +204,20 @@ func (st *serverTester) Close() { st.conn.Close() } if st.cmd != nil { - st.cmd.Process.Kill() - st.cmd.Wait() - // workaround to unreliable Process.Signal() - time.Sleep(150 * time.Millisecond) + done := make(chan struct{}) + go func() { + st.cmd.Wait() + done <- struct{}{} + }() + + st.cmd.Process.Signal(syscall.SIGQUIT) + + select { + case <-done: + case <-time.After(10 * time.Second): + st.cmd.Process.Kill() + <-done + } } if st.ts != nil { st.ts.Close()