1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #16889 from cxxly/16756-refactor-docker_cli_wait_test

use of checkers on Integration test
This commit is contained in:
Vincent Demeester 2015-10-11 10:12:42 +02:00
commit fb8217ee62

View file

@ -6,6 +6,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -14,14 +15,11 @@ func (s *DockerSuite) TestWaitNonBlockedExitZero(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "true")
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
if err := waitInspect(containerID, "{{.State.Running}}", "false", 30*time.Second); err != nil { err := waitInspect(containerID, "{{.State.Running}}", "false", 30*time.Second)
c.Fatal("Container should have stopped by now") c.Assert(err, checker.IsNil) //Container should have stopped by now
}
out, _ = dockerCmd(c, "wait", containerID) out, _ = dockerCmd(c, "wait", containerID)
if strings.TrimSpace(out) != "0" { c.Assert(strings.TrimSpace(out), checker.Equals, "0", check.Commentf("failed to set up container, %v", out))
c.Fatal("failed to set up container", out)
}
} }
@ -33,7 +31,7 @@ func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 0' TERM; while true; do usleep 10; done") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 0' TERM; while true; do usleep 10; done")
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
c.Assert(waitRun(containerID), check.IsNil) c.Assert(waitRun(containerID), checker.IsNil)
chWait := make(chan string) chWait := make(chan string)
go func() { go func() {
@ -46,9 +44,7 @@ func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) {
select { select {
case status := <-chWait: case status := <-chWait:
if strings.TrimSpace(status) != "0" { c.Assert(strings.TrimSpace(status), checker.Equals, "0", check.Commentf("expected exit 0, got %s", status))
c.Fatalf("expected exit 0, got %s", status)
}
case <-time.After(2 * time.Second): case <-time.After(2 * time.Second):
c.Fatal("timeout waiting for `docker wait` to exit") c.Fatal("timeout waiting for `docker wait` to exit")
} }
@ -60,14 +56,10 @@ func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "exit 99") out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "exit 99")
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
if err := waitInspect(containerID, "{{.State.Running}}", "false", 30*time.Second); err != nil { err := waitInspect(containerID, "{{.State.Running}}", "false", 30*time.Second)
c.Fatal("Container should have stopped by now") c.Assert(err, checker.IsNil) //Container should have stopped by now
}
out, _ = dockerCmd(c, "wait", containerID) out, _ = dockerCmd(c, "wait", containerID)
if strings.TrimSpace(out) != "99" { c.Assert(strings.TrimSpace(out), checker.Equals, "99", check.Commentf("failed to set up container, %v", out))
c.Fatal("failed to set up container", out)
}
} }
@ -77,16 +69,13 @@ func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 99' TERM; while true; do usleep 10; done") out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 99' TERM; while true; do usleep 10; done")
containerID := strings.TrimSpace(out) containerID := strings.TrimSpace(out)
c.Assert(waitRun(containerID), check.IsNil) c.Assert(waitRun(containerID), checker.IsNil)
chWait := make(chan error) chWait := make(chan error)
waitCmd := exec.Command(dockerBinary, "wait", containerID) waitCmd := exec.Command(dockerBinary, "wait", containerID)
waitCmdOut := bytes.NewBuffer(nil) waitCmdOut := bytes.NewBuffer(nil)
waitCmd.Stdout = waitCmdOut waitCmd.Stdout = waitCmdOut
if err := waitCmd.Start(); err != nil { c.Assert(waitCmd.Start(), checker.IsNil)
c.Fatal(err)
}
go func() { go func() {
chWait <- waitCmd.Wait() chWait <- waitCmd.Wait()
}() }()
@ -95,16 +84,10 @@ func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) {
select { select {
case err := <-chWait: case err := <-chWait:
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err)
}
status, err := waitCmdOut.ReadString('\n') status, err := waitCmdOut.ReadString('\n')
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err) c.Assert(strings.TrimSpace(status), checker.Equals, "99", check.Commentf("expected exit 99, got %s", status))
}
if strings.TrimSpace(status) != "99" {
c.Fatalf("expected exit 99, got %s", status)
}
case <-time.After(2 * time.Second): case <-time.After(2 * time.Second):
waitCmd.Process.Kill() waitCmd.Process.Kill()
c.Fatal("timeout waiting for `docker wait` to exit") c.Fatal("timeout waiting for `docker wait` to exit")