Skip to content

Commit

Permalink
Merge pull request #9796 from LK4D4/fix_test_daemon
Browse files Browse the repository at this point in the history
More graceful stop for testing daemon
  • Loading branch information
Jessie Frazelle committed Dec 29, 2014
2 parents 43886de + 8dc86c0 commit 7156fb2
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions integration-cli/docker_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,33 @@ func (d *Daemon) Stop() error {
if err := d.cmd.Process.Signal(os.Interrupt); err != nil {
return fmt.Errorf("could not send signal: %v", err)
}
out:
out1:
for {
select {
case err := <-d.wait:
return err
case <-time.After(20 * time.Second):
case <-time.After(15 * time.Second):
// time for stopping jobs and run onShutdown hooks
d.t.Log("timeout")
break out
break out1
}
}

out2:
for {
select {
case err := <-d.wait:
return err
case <-tick:
d.t.Logf("Attempt #%d: daemon is still running with pid %d", i+1, d.cmd.Process.Pid)
i++
if i > 4 {
d.t.Log("tried to interrupt daemon for %d times, now try to kill it", i)
break out2
}
d.t.Logf("Attempt #%d: daemon is still running with pid %d", i, d.cmd.Process.Pid)
if err := d.cmd.Process.Signal(os.Interrupt); err != nil {
return fmt.Errorf("could not send signal: %v", err)
}
i++
}
}

Expand Down

0 comments on commit 7156fb2

Please sign in to comment.