mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Added integration tests for docker wait command
Signed-off-by: Pradeep Chhetri <pradeep@indix.com>
This commit is contained in:
parent
88924993a2
commit
1401b8fe0d
1 changed files with 121 additions and 0 deletions
121
integration-cli/docker_cli_wait_test.go
Normal file
121
integration-cli/docker_cli_wait_test.go
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// non-blocking wait with 0 exit code
|
||||||
|
func TestWaitNonBlockedExitZero(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "true")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
containerID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
|
status := "true"
|
||||||
|
for i := 0; status != "false"; i++ {
|
||||||
|
runCmd = exec.Command(dockerBinary, "inspect", "--format='{{.State.Running}}'", containerID)
|
||||||
|
status, _, err = runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(status, err)
|
||||||
|
}
|
||||||
|
status = stripTrailingCharacters(status)
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
if i >= 60 {
|
||||||
|
t.Fatal("Container should have stopped by now")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "wait", containerID)
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
|
||||||
|
if err != nil || stripTrailingCharacters(out) != "0" {
|
||||||
|
t.Fatal("failed to set up container", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("wait - non-blocking wait with 0 exit code")
|
||||||
|
}
|
||||||
|
|
||||||
|
// blocking wait with 0 exit code
|
||||||
|
func TestWaitBlockedExitZero(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
containerID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "wait", containerID)
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
|
||||||
|
if err != nil || stripTrailingCharacters(out) != "0" {
|
||||||
|
t.Fatal("failed to set up container", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("wait - blocking wait with 0 exit code")
|
||||||
|
}
|
||||||
|
|
||||||
|
// non-blocking wait with random exit code
|
||||||
|
func TestWaitNonBlockedExitRandom(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "exit 99")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
containerID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
|
status := "true"
|
||||||
|
for i := 0; status != "false"; i++ {
|
||||||
|
runCmd = exec.Command(dockerBinary, "inspect", "--format='{{.State.Running}}'", containerID)
|
||||||
|
status, _, err = runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(status, err)
|
||||||
|
}
|
||||||
|
status = stripTrailingCharacters(status)
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
if i >= 60 {
|
||||||
|
t.Fatal("Container should have stopped by now")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "wait", containerID)
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
|
||||||
|
if err != nil || stripTrailingCharacters(out) != "99" {
|
||||||
|
t.Fatal("failed to set up container", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("wait - non-blocking wait with random exit code")
|
||||||
|
}
|
||||||
|
|
||||||
|
// blocking wait with random exit code
|
||||||
|
func TestWaitBlockedExitRandom(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10; exit 99")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
containerID := stripTrailingCharacters(out)
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "wait", containerID)
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
|
||||||
|
if err != nil || stripTrailingCharacters(out) != "99" {
|
||||||
|
t.Fatal("failed to set up container", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("wait - blocking wait with random exit code")
|
||||||
|
}
|
Loading…
Reference in a new issue