[integration-cli] fix race condition in kill tests
Fixes a race condition in the kill tests where the container would be killed but inspected before it's state changed. Fixes this by waiting for a state change instead. Signed-off-by: Christopher Jones <tophj@linux.vnet.ibm.com>
This commit is contained in:
parent
fe77fc5bf1
commit
ff42a1ab53
2 changed files with 15 additions and 2 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/go-check/check"
|
||||
|
@ -15,6 +16,7 @@ func (s *DockerSuite) TestKillContainer(c *check.C) {
|
|||
c.Assert(waitRun(cleanedContainerID), check.IsNil)
|
||||
|
||||
dockerCmd(c, "kill", cleanedContainerID)
|
||||
c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-q")
|
||||
c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running"))
|
||||
|
@ -26,6 +28,7 @@ func (s *DockerSuite) TestKillOffStoppedContainer(c *check.C) {
|
|||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
dockerCmd(c, "stop", cleanedContainerID)
|
||||
c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil)
|
||||
|
||||
_, _, err := dockerCmdWithError("kill", "-s", "30", cleanedContainerID)
|
||||
c.Assert(err, check.Not(check.IsNil), check.Commentf("Container %s is not running", cleanedContainerID))
|
||||
|
@ -39,6 +42,7 @@ func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) {
|
|||
c.Assert(waitRun(cleanedContainerID), check.IsNil)
|
||||
|
||||
dockerCmd(c, "kill", cleanedContainerID)
|
||||
c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-q")
|
||||
c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running"))
|
||||
|
@ -54,6 +58,7 @@ func (s *DockerSuite) TestKillWithSignal(c *check.C) {
|
|||
c.Assert(waitRun(cid), check.IsNil)
|
||||
|
||||
dockerCmd(c, "kill", "-s", "SIGWINCH", cid)
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
|
||||
running := inspectField(c, cid, "State.Running")
|
||||
|
||||
|
@ -67,8 +72,10 @@ func (s *DockerSuite) TestKillWithStopSignalWithSameSignalShouldDisableRestartPo
|
|||
cid := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(cid), check.IsNil)
|
||||
|
||||
// Let's docker send a CONT signal to the container
|
||||
// Let docker send a TERM signal to the container
|
||||
// It will kill the process and disable the restart policy
|
||||
dockerCmd(c, "kill", "-s", "TERM", cid)
|
||||
c.Assert(waitExited(cid, 10*time.Second), check.IsNil)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-q")
|
||||
c.Assert(out, checker.Not(checker.Contains), cid, check.Commentf("killed container is still running"))
|
||||
|
@ -81,9 +88,10 @@ func (s *DockerSuite) TestKillWithStopSignalWithDifferentSignalShouldKeepRestart
|
|||
cid := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(cid), check.IsNil)
|
||||
|
||||
// Let's docker send a TERM signal to the container
|
||||
// Let docker send a TERM signal to the container
|
||||
// It will kill the process, but not disable the restart policy
|
||||
dockerCmd(c, "kill", "-s", "TERM", cid)
|
||||
c.Assert(waitRestart(cid, 10*time.Second), check.IsNil)
|
||||
|
||||
// Restart policy should still be in place, so it should be still running
|
||||
c.Assert(waitRun(cid), check.IsNil)
|
||||
|
|
|
@ -1401,6 +1401,11 @@ func waitForContainer(contID string, args ...string) error {
|
|||
return waitRun(contID)
|
||||
}
|
||||
|
||||
// waitRestart will wait for the specified container to restart once
|
||||
func waitRestart(contID string, duration time.Duration) error {
|
||||
return waitInspect(contID, "{{.RestartCount}}", "1", duration)
|
||||
}
|
||||
|
||||
// waitRun will wait for the specified container to be running, maximum 5 seconds.
|
||||
func waitRun(contID string) error {
|
||||
return waitInspect(contID, "{{.State.Running}}", "true", 5*time.Second)
|
||||
|
|
Loading…
Add table
Reference in a new issue