Merge pull request #28220 from tophj-ibm/test-killing-with-stop-signals
[integration-cli] fix race condition in kill tests
This commit is contained in:
commit
7df0ed49d7
2 changed files with 17 additions and 4 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")
|
||||
|
||||
|
@ -63,12 +68,14 @@ func (s *DockerSuite) TestKillWithSignal(c *check.C) {
|
|||
func (s *DockerSuite) TestKillWithStopSignalWithSameSignalShouldDisableRestartPolicy(c *check.C) {
|
||||
// Cannot port to Windows - does not support signals int the same way as Linux does
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "--stop-signal=TERM", "busybox", "top")
|
||||
out, _ := dockerCmd(c, "run", "-d", "--stop-signal=TERM", "--restart=always", "busybox", "top")
|
||||
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"))
|
||||
|
@ -77,13 +84,14 @@ func (s *DockerSuite) TestKillWithStopSignalWithSameSignalShouldDisableRestartPo
|
|||
func (s *DockerSuite) TestKillWithStopSignalWithDifferentSignalShouldKeepRestartPolicy(c *check.C) {
|
||||
// Cannot port to Windows - does not support signals int the same way as Linux does
|
||||
testRequires(c, DaemonIsLinux)
|
||||
out, _ := dockerCmd(c, "run", "-d", "--stop-signal=CONT", "busybox", "top")
|
||||
out, _ := dockerCmd(c, "run", "-d", "--stop-signal=CONT", "--restart=always", "busybox", "top")
|
||||
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