integration: Robust process termination

This commit is contained in:
Tatsuhiro Tsujikawa 2015-09-24 23:37:01 +09:00
parent f470d1cc06
commit bb4ab7e333
1 changed files with 15 additions and 4 deletions

View File

@ -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()