|
@@ -44,19 +44,29 @@ func (s *DockerSuite) TestWaitNonBlockedExitZero(c *check.C) {
|
|
|
|
|
|
// blocking wait with 0 exit code
|
|
// blocking wait with 0 exit code
|
|
func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) {
|
|
func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) {
|
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 0' SIGTERM; while true; do sleep 0.01; done")
|
|
|
|
+ containerID := strings.TrimSpace(out)
|
|
|
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10")
|
|
|
|
- out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
- if err != nil {
|
|
|
|
- c.Fatal(out, err)
|
|
|
|
|
|
+ if err := waitRun(containerID); err != nil {
|
|
|
|
+ c.Fatal(err)
|
|
}
|
|
}
|
|
- containerID := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
- runCmd = exec.Command(dockerBinary, "wait", containerID)
|
|
|
|
- out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
|
|
+ chWait := make(chan string)
|
|
|
|
+ go func() {
|
|
|
|
+ out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "wait", containerID))
|
|
|
|
+ chWait <- out
|
|
|
|
+ }()
|
|
|
|
|
|
- if err != nil || strings.TrimSpace(out) != "0" {
|
|
|
|
- c.Fatal("failed to set up container", out, err)
|
|
|
|
|
|
+ time.Sleep(100 * time.Millisecond)
|
|
|
|
+ dockerCmd(c, "stop", containerID)
|
|
|
|
+
|
|
|
|
+ select {
|
|
|
|
+ case status := <-chWait:
|
|
|
|
+ if strings.TrimSpace(status) != "0" {
|
|
|
|
+ c.Fatalf("expected exit 0, got %s", status)
|
|
|
|
+ }
|
|
|
|
+ case <-time.After(2 * time.Second):
|
|
|
|
+ c.Fatal("timeout waiting for `docker wait` to exit")
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -97,19 +107,30 @@ func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) {
|
|
|
|
|
|
// blocking wait with random exit code
|
|
// blocking wait with random exit code
|
|
func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) {
|
|
func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) {
|
|
-
|
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10; exit 99")
|
|
|
|
- out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
- if err != nil {
|
|
|
|
- c.Fatal(out, err)
|
|
|
|
- }
|
|
|
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "trap 'exit 99' SIGTERM; while true; do sleep 0.01; done")
|
|
containerID := strings.TrimSpace(out)
|
|
containerID := strings.TrimSpace(out)
|
|
|
|
+ if err := waitRun(containerID); err != nil {
|
|
|
|
+ c.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ if err := waitRun(containerID); err != nil {
|
|
|
|
+ c.Fatal(err)
|
|
|
|
+ }
|
|
|
|
|
|
- runCmd = exec.Command(dockerBinary, "wait", containerID)
|
|
|
|
- out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
|
|
+ chWait := make(chan string)
|
|
|
|
+ go func() {
|
|
|
|
+ out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "wait", containerID))
|
|
|
|
+ chWait <- out
|
|
|
|
+ }()
|
|
|
|
|
|
- if err != nil || strings.TrimSpace(out) != "99" {
|
|
|
|
- c.Fatal("failed to set up container", out, err)
|
|
|
|
- }
|
|
|
|
|
|
+ time.Sleep(100 * time.Millisecond)
|
|
|
|
+ dockerCmd(c, "stop", containerID)
|
|
|
|
|
|
|
|
+ select {
|
|
|
|
+ case status := <-chWait:
|
|
|
|
+ if strings.TrimSpace(status) != "99" {
|
|
|
|
+ c.Fatalf("expected exit 99, got %s", status)
|
|
|
|
+ }
|
|
|
|
+ case <-time.After(2 * time.Second):
|
|
|
|
+ c.Fatal("timeout waiting for `docker wait` to exit")
|
|
|
|
+ }
|
|
}
|
|
}
|