diff --git a/test/integration/api/cp.bats b/test/integration/api/cp.bats index aecb205008..569ad10e0d 100644 --- a/test/integration/api/cp.bats +++ b/test/integration/api/cp.bats @@ -18,11 +18,9 @@ function teardown() { # create the container docker_swarm run -d --name test_container busybox sleep 500 - # make sure container is up and no comming file - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # make sure container is up + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" # grab the checksum of the test file inside the container. run docker_swarm exec test_container md5sum $test_file @@ -30,10 +28,10 @@ function teardown() { [ "${#lines[@]}" -ge 1 ] # get the checksum number - container_checksum=`echo ${lines[0]} | awk '{print $1}'` + container_checksum=$(echo ${lines[0]} | awk '{print $1}') # host file - host_file=$temp_dest/`basename $test_file` + host_file=$temp_dest/$(basename $test_file) [ ! -f $host_file ] # copy the test file from the container to the host. @@ -44,10 +42,10 @@ function teardown() { run md5sum $host_file [ "$status" -eq 0 ] [ "${#lines[@]}" -ge 1 ] - host_checksum=`echo ${lines[0]} | awk '{print $1}'` + host_checksum=$(echo ${lines[0]} | awk '{print $1}') # Verify that they match. - [[ "${container_checksum}" == "${host_checksum}" ]] + [ "${container_checksum}" == "${host_checksum}" ] # after ok, remove temp directory and file - rm -rf $temp_dest + rm -rf "$temp_dest" } diff --git a/test/integration/api/diff.bats b/test/integration/api/diff.bats index a68ee361d7..26f518ad59 100644 --- a/test/integration/api/diff.bats +++ b/test/integration/api/diff.bats @@ -13,12 +13,10 @@ function teardown() { docker_swarm run -d --name test_container busybox sleep 500 # make sure container is up - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" - # no changs + # no changes run docker_swarm diff test_container [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 0 ] @@ -29,5 +27,5 @@ function teardown() { # verify run docker_swarm diff test_container [ "$status" -eq 0 ] - [[ "${lines[*]}" == *"diff.txt"* ]] + [[ "${output}" == *"diff.txt"* ]] } diff --git a/test/integration/api/exec.bats b/test/integration/api/exec.bats index 45a241c9fd..f6b1b4a18a 100644 --- a/test/integration/api/exec.bats +++ b/test/integration/api/exec.bats @@ -20,15 +20,10 @@ function teardown() { docker_swarm start test_container # make sure container is up and not paused - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] - [[ "${lines[1]}" != *"Paused"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" - run docker_swarm exec test_container ls + run docker_swarm exec test_container echo foobar [ "$status" -eq 0 ] - [ "${#lines[@]}" -ge 2 ] - [[ "${lines[0]}" == *"bin"* ]] - [[ "${lines[1]}" == *"dev"* ]] + [ "$output" == "foobar" ] } diff --git a/test/integration/api/kill.bats b/test/integration/api/kill.bats index e59b5b51dd..395f86aded 100644 --- a/test/integration/api/kill.bats +++ b/test/integration/api/kill.bats @@ -14,17 +14,14 @@ function teardown() { docker_swarm run -d --name test_container busybox sleep 1000 # make sure container is up before killing - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" # kill docker_swarm kill test_container # verify - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Exited"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=exited) ]" + [ $(docker_swarm inspect -f '{{ .State.ExitCode }}' test_container) -eq 137 ] } diff --git a/test/integration/api/pause.bats b/test/integration/api/pause.bats index be794fabf6..6e0ab45107 100644 --- a/test/integration/api/pause.bats +++ b/test/integration/api/pause.bats @@ -3,6 +3,8 @@ load ../helpers function teardown() { + # if the state of the container is paused, it can't be removed(rm -f) + run docker_swarm unpause test_container swarm_manage_cleanup stop_docker } @@ -14,19 +16,12 @@ function teardown() { docker_swarm run -d --name test_container busybox sleep 1000 # make sure container is up - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" docker_swarm pause test_container # verify - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Paused"* ]] - - # if the state of the container is paused, it can't be removed(rm -f) - docker_swarm unpause test_container + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=paused) ]" } diff --git a/test/integration/api/port.bats b/test/integration/api/port.bats index 2db3f416a5..b1f404eb53 100644 --- a/test/integration/api/port.bats +++ b/test/integration/api/port.bats @@ -13,10 +13,8 @@ function teardown() { docker_swarm run -d -p 8000 --name test_container busybox sleep 500 # make sure container is up - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" # port verify run docker_swarm port test_container diff --git a/test/integration/api/restart.bats b/test/integration/api/restart.bats index 4c7f53cf3c..f11fce3cbb 100644 --- a/test/integration/api/restart.bats +++ b/test/integration/api/restart.bats @@ -14,17 +14,18 @@ function teardown() { docker_swarm run -d --name test_container busybox sleep 1000 # make sure container is up - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" + + # Keep track of when the container was started. + local started_at=$(docker_swarm inspect -f '{{ .State.StartedAt }}' test_container) # restart docker_swarm restart test_container # verify run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" + [ "$(docker_swarm inspect -f '{{ .State.StartedAt }}' test_container)" != "$started_at" ] } diff --git a/test/integration/api/rm.bats b/test/integration/api/rm.bats index 5b190ee9b3..76a25bee25 100644 --- a/test/integration/api/rm.bats +++ b/test/integration/api/rm.bats @@ -32,10 +32,8 @@ function teardown() { docker_swarm run -d --name test_container busybox sleep 500 # make sure container exsists and is up - run docker_swarm ps -a - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" # rm, remove a running container, return error run docker_swarm rm test_container diff --git a/test/integration/api/run.bats b/test/integration/api/run.bats index 6b736b61f0..e49560ffd8 100644 --- a/test/integration/api/run.bats +++ b/test/integration/api/run.bats @@ -18,9 +18,7 @@ function teardown() { # run docker_swarm run -d --name test_container busybox sleep 100 - # verify, container exists - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${output}" == *"test_container"* ]] - [[ "${output}" == *"Up"* ]] + # verify, container is running + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" } diff --git a/test/integration/api/start.bats b/test/integration/api/start.bats index 0dada7294c..2efe977f0e 100644 --- a/test/integration/api/start.bats +++ b/test/integration/api/start.bats @@ -20,10 +20,9 @@ function teardown() { [[ "${lines[1]}" == *"test_container"* ]] # start - run docker_swarm start test_container - [ "$status" -eq 0 ] - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + docker_swarm start test_container + + # Verify + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" } diff --git a/test/integration/api/stats.bats b/test/integration/api/stats.bats index d79505cfb4..47392f0c0b 100644 --- a/test/integration/api/stats.bats +++ b/test/integration/api/stats.bats @@ -16,23 +16,19 @@ function teardown() { docker_swarm run -d --name test_container busybox sleep 50 # make sure container is up - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" # storage the stats output in TEMP_FILE # it will stop automatically when manager stop docker_swarm stats test_container > $TEMP_FILE & # retry until TEMP_FILE is not empty - retry 5 1 [ -s $TEMP_FILE ] + retry 5 1 eval "[ -s $TEMP_FILE ]" - # if "CPU %" in TEMP_FILE, status is 0 - run grep "CPU %" $TEMP_FILE - [ "$status" -eq 0 ] - run grep "MEM USAGE/LIMIT" $TEMP_FILE - [ "$status" -eq 0 ] + # verify content + grep -q "CPU %" "$TEMP_FILE" + grep -q "MEM USAGE/LIMIT" "$TEMP_FILE" rm -f $TEMP_FILE } diff --git a/test/integration/api/stop.bats b/test/integration/api/stop.bats index 627a00efca..188a984e9c 100644 --- a/test/integration/api/stop.bats +++ b/test/integration/api/stop.bats @@ -14,17 +14,13 @@ function teardown() { docker_swarm run -d --name test_container busybox sleep 500 # make sure container is up before stop - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" # stop docker_swarm stop test_container # verify - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Exited"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=exited) ]" } diff --git a/test/integration/api/top.bats b/test/integration/api/top.bats index 3655774575..65b3888ef5 100644 --- a/test/integration/api/top.bats +++ b/test/integration/api/top.bats @@ -14,10 +14,8 @@ function teardown() { docker_swarm run -d --name test_container busybox sleep 500 # make sure container is running - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" run docker_swarm top test_container [ "$status" -eq 0 ] diff --git a/test/integration/api/unpause.bats b/test/integration/api/unpause.bats index 4ebf023b78..647c1774a7 100644 --- a/test/integration/api/unpause.bats +++ b/test/integration/api/unpause.bats @@ -14,26 +14,19 @@ function teardown() { docker_swarm run -d --name test_container busybox sleep 1000 # make sure container is up - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" # pause docker_swarm pause test_container - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Paused"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=paused) ]" # unpause docker_swarm unpause test_container # verify - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] - [[ "${lines[1]}" != *"Paused"* ]] + # FIXME(#748): Retry required because of race condition. + retry 5 0.5 eval "[ -n $(docker_swarm ps -q --filter=name=test_container --filter=status=running) ]" } diff --git a/test/integration/api/wait.bats b/test/integration/api/wait.bats index feb42350e5..86df0ddc26 100644 --- a/test/integration/api/wait.bats +++ b/test/integration/api/wait.bats @@ -14,15 +14,8 @@ function teardown() { # run after 1 seconds, test_container will exit docker_swarm run -d --name test_container busybox sleep 1 - # make sure container exists and is up - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - [[ "${lines[1]}" == *"Up"* ]] - # wait until exist(after 1 seconds) run timeout 5 docker -H $SWARM_HOST wait test_container - - [ "${#lines[@]}" -eq 1 ] + [ "$status" -eq 0 ] [[ "${output}" == "0" ]] }