From f83b3daabbf8d2be500378ecaa4aaff5003b0397 Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Wed, 22 Apr 2015 06:16:12 +0800 Subject: [PATCH 1/6] add events-search-stats-version-wait integration test Signed-off-by: Xian Chaobo --- test/integration/api.bats | 108 ++++++++++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 10 deletions(-) diff --git a/test/integration/api.bats b/test/integration/api.bats index 8d16247f8f..6c2d91faaf 100644 --- a/test/integration/api.bats +++ b/test/integration/api.bats @@ -182,9 +182,29 @@ function teardown() { [[ "${lines[*]}" == *"diff.txt"* ]] } -# FIXME @test "docker events" { - skip + TEMP_FILE=$(mktemp) + start_docker 3 + swarm_manage + + # start events, report real time events to TEMP_FILE + docker_swarm events > $TEMP_FILE & + + # events: create container + run docker_swarm create --name test_container busybox sleep 100 + [ "$status" -eq 0 ] + # events: start container + run docker_swarm start test_container + [ "$status" -eq 0 ] + + # make sure $TEMP_FILE exists and is not empty + [ -s $TEMP_FILE ] + + # verify + run cat $TEMP_FILE + [ "$status" -eq 0 ] + [[ "${output}" == *"create"* ]] + [[ "${output}" == *"start"* ]] } @test "docker exec" { @@ -748,9 +768,27 @@ function teardown() { rm -f $temp_file_name_o } -# FIXME @test "docker search" { - skip + start_docker 3 + swarm_manage + + TEMP_NAME=noimage$RANDOM + # search image (not exist), the name of images only [a-z0-9-_.] are allowed + run docker_swarm search $TEMP_NAME + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 1 ] + [[ "${lines[0]}" == *"DESCRIPTION"* ]] + + # search busybox (image exist) + run docker_swarm search busybox + [ "$status" -eq 0 ] + + # search existed image, output: latest + header at least + [ "${#lines[@]}" -ge 2 ] + # Every line should contain "busybox" exclude the first head line + for((i=1; i<${#lines[@]}; i++)); do + [[ "${lines[i]}" == *"busybox"* ]] + done } @test "docker start" { @@ -775,9 +813,32 @@ function teardown() { [[ "${lines[1]}" == *"Up"* ]] } -# FIXME @test "docker stats" { - skip + TEMP_FILE=$(mktemp) + start_docker 3 + swarm_manage + # stats running container + run docker_swarm run -d --name test_container busybox sleep 50 + [ "$status" -eq 0 ] + + # make sure container is up + run docker_swarm ps -l + [ "${#lines[@]}" -eq 2 ] + [[ "${lines[1]}" == *"test_container"* ]] + [[ "${lines[1]}" == *"Up"* ]] + + # storage the real time output of stats in TEMP_FILE + docker_swarm stats test_container > $TEMP_FILE & + + # make sure TEMP_FILE exists and is not empty + sleep 3 + [ -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 ] } @test "docker stop" { @@ -880,12 +941,39 @@ function teardown() { [[ "${lines[1]}" != *"Paused"* ]] } -# FIXME @test "docker version" { - skip + start_docker 3 + swarm_manage + + # version + run docker_swarm version + [ "$status" -eq 0 ] + [ "${#lines[@]}" -ge 8 ] + + # verify + client_reg='^Client version: [0-9]+\.[0-9]+\.[0-9]+$' + server_reg='^Server version: swarm/[0-9]+\.[0-9]+\.[0-9]+$' + [[ "${lines[0]}" =~ $client_reg ]] + [[ "${lines[5]}" =~ $server_reg ]] } -# FIXME @test "docker wait" { - skip + start_docker 3 + swarm_manage + + # run after 10 seconds, test_container will exit + run docker_swarm run -d --name test_container busybox sleep 10 + [ "$status" -eq 0 ] + + # 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 10 seconds) + run docker_swarm wait test_container + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 1 ] + [[ "${lines[0]}" == "0" ]] } From d1bc9e34071682c2884b226a25693bbdc0eb93f3 Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Wed, 22 Apr 2015 12:07:02 +0800 Subject: [PATCH 2/6] bug fix Signed-off-by: Xian Chaobo --- test/integration/api.bats | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/test/integration/api.bats b/test/integration/api.bats index 6c2d91faaf..02f6319100 100644 --- a/test/integration/api.bats +++ b/test/integration/api.bats @@ -772,9 +772,8 @@ function teardown() { start_docker 3 swarm_manage - TEMP_NAME=noimage$RANDOM # search image (not exist), the name of images only [a-z0-9-_.] are allowed - run docker_swarm search $TEMP_NAME + run docker_swarm search does_not_exist [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 1 ] [[ "${lines[0]}" == *"DESCRIPTION"* ]] @@ -830,9 +829,13 @@ function teardown() { # storage the real time output of stats in TEMP_FILE docker_swarm stats test_container > $TEMP_FILE & + local attempts=0 + local max_attempts=5 # make sure TEMP_FILE exists and is not empty - sleep 3 - [ -s $TEMP_FILE ] + until [ -s $TEMP_FILE ] || [ $attempts -ge $max_attempts ]; do + sleep 0.5 + attempts=$[$attempts+1] + done # if "CPU %" in TEMP_FILE, status is 0 run grep "CPU %" $TEMP_FILE @@ -958,11 +961,12 @@ function teardown() { } @test "docker wait" { + TEMP_FILE=$(mktemp) start_docker 3 swarm_manage - - # run after 10 seconds, test_container will exit - run docker_swarm run -d --name test_container busybox sleep 10 + + # run after 3 seconds, test_container will exit + run docker_swarm run -d --name test_container busybox sleep 3 [ "$status" -eq 0 ] # make sure container exists and is up @@ -971,9 +975,20 @@ function teardown() { [[ "${lines[1]}" == *"test_container"* ]] [[ "${lines[1]}" == *"Up"* ]] - # wait until exist(after 10 seconds) - run docker_swarm wait test_container + # wait until exist(after 3 seconds) + docker_swarm wait test_container > $TEMP_FILE & + WAIT_PID=$! + + # after 5 secondes, cat $TEMP_FILE + sleep 5 + run cat $TEMP_FILE [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 1 ] [[ "${lines[0]}" == "0" ]] + + # after sucess, if the wait process still exist then kill + run ps -p $WAIT_PID + if [ "$status" -eq 0 ]; then + kill -9 $WAIT_PID + fi } From d884b462728f0e9ed8c518d7cd6f1498adca48a2 Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Wed, 22 Apr 2015 15:29:39 +0800 Subject: [PATCH 3/6] specific node for events Signed-off-by: Xian Chaobo --- test/integration/api.bats | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/integration/api.bats b/test/integration/api.bats index 02f6319100..618432dc48 100644 --- a/test/integration/api.bats +++ b/test/integration/api.bats @@ -190,8 +190,8 @@ function teardown() { # start events, report real time events to TEMP_FILE docker_swarm events > $TEMP_FILE & - # events: create container - run docker_swarm create --name test_container busybox sleep 100 + # events: create container on node-0 + run docker_swarm create --name test_container -e constraint:node==node-0 busybox sleep 100 [ "$status" -eq 0 ] # events: start container run docker_swarm start test_container @@ -203,8 +203,12 @@ function teardown() { # verify run cat $TEMP_FILE [ "$status" -eq 0 ] + [[ "${output}" == *"node:node-0"* ]] [[ "${output}" == *"create"* ]] [[ "${output}" == *"start"* ]] + + # after ok, remove the $TEMP_FILE + rm -f $TEMP_FILE } @test "docker exec" { From 2f049ccf4f9f9a069018ed61c3857b1465cdf343 Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Mon, 4 May 2015 14:22:45 +0800 Subject: [PATCH 4/6] use retry Signed-off-by: Xian Chaobo --- test/integration/api.bats | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/test/integration/api.bats b/test/integration/api.bats index 618432dc48..d0c6b994fb 100644 --- a/test/integration/api.bats +++ b/test/integration/api.bats @@ -820,6 +820,7 @@ function teardown() { TEMP_FILE=$(mktemp) start_docker 3 swarm_manage + # stats running container run docker_swarm run -d --name test_container busybox sleep 50 [ "$status" -eq 0 ] @@ -830,22 +831,19 @@ function teardown() { [[ "${lines[1]}" == *"test_container"* ]] [[ "${lines[1]}" == *"Up"* ]] - # storage the real time output of stats in TEMP_FILE + # storage the stats output in TEMP_FILE docker_swarm stats test_container > $TEMP_FILE & - local attempts=0 - local max_attempts=5 - # make sure TEMP_FILE exists and is not empty - until [ -s $TEMP_FILE ] || [ $attempts -ge $max_attempts ]; do - sleep 0.5 - attempts=$[$attempts+1] - done + # retry until TEMP_FILE is not empty + retry 5 1 [ -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 ] + + rm -f $TEMP_FILE } @test "docker stop" { @@ -969,8 +967,8 @@ function teardown() { start_docker 3 swarm_manage - # run after 3 seconds, test_container will exit - run docker_swarm run -d --name test_container busybox sleep 3 + # run after 1 seconds, test_container will exit + run docker_swarm run -d --name test_container busybox sleep 1 [ "$status" -eq 0 ] # make sure container exists and is up @@ -979,20 +977,15 @@ function teardown() { [[ "${lines[1]}" == *"test_container"* ]] [[ "${lines[1]}" == *"Up"* ]] - # wait until exist(after 3 seconds) + # wait until exist(after 1 seconds) docker_swarm wait test_container > $TEMP_FILE & - WAIT_PID=$! - # after 5 secondes, cat $TEMP_FILE - sleep 5 + # retry until $TEMP_FILE is not empty + retry 5 1 [ -s $TEMP_FILE ] + run cat $TEMP_FILE - [ "$status" -eq 0 ] [ "${#lines[@]}" -eq 1 ] - [[ "${lines[0]}" == "0" ]] + [[ "${output}" == "0" ]] - # after sucess, if the wait process still exist then kill - run ps -p $WAIT_PID - if [ "$status" -eq 0 ]; then - kill -9 $WAIT_PID - fi + rm -f $TEMP_FILE } From da2261f0be13f7e07c1375041a9eda221bc3e2bc Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Mon, 4 May 2015 21:28:20 +0800 Subject: [PATCH 5/6] using timeout in wait Signed-off-by: Xian Chaobo --- test/integration/api.bats | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/test/integration/api.bats b/test/integration/api.bats index d0c6b994fb..8534fabf98 100644 --- a/test/integration/api.bats +++ b/test/integration/api.bats @@ -188,6 +188,7 @@ function teardown() { swarm_manage # start events, report real time events to TEMP_FILE + # it will stop automatically when manager stop docker_swarm events > $TEMP_FILE & # events: create container on node-0 @@ -197,9 +198,6 @@ function teardown() { run docker_swarm start test_container [ "$status" -eq 0 ] - # make sure $TEMP_FILE exists and is not empty - [ -s $TEMP_FILE ] - # verify run cat $TEMP_FILE [ "$status" -eq 0 ] @@ -820,7 +818,7 @@ function teardown() { TEMP_FILE=$(mktemp) start_docker 3 swarm_manage - + # stats running container run docker_swarm run -d --name test_container busybox sleep 50 [ "$status" -eq 0 ] @@ -832,9 +830,10 @@ function teardown() { [[ "${lines[1]}" == *"Up"* ]] # 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 until TEMP_FILE is not empty retry 5 1 [ -s $TEMP_FILE ] # if "CPU %" in TEMP_FILE, status is 0 @@ -978,10 +977,7 @@ function teardown() { [[ "${lines[1]}" == *"Up"* ]] # wait until exist(after 1 seconds) - docker_swarm wait test_container > $TEMP_FILE & - - # retry until $TEMP_FILE is not empty - retry 5 1 [ -s $TEMP_FILE ] + timeout 5 docker -H $SWARM_HOST wait test_container > $TEMP_FILE run cat $TEMP_FILE [ "${#lines[@]}" -eq 1 ] From 35026de4c42436f269c5f7d7186c91f98c65c263 Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Tue, 5 May 2015 12:31:09 +0800 Subject: [PATCH 6/6] bug fix Signed-off-by: Xian Chaobo --- test/integration/api.bats | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/integration/api.bats b/test/integration/api.bats index 8534fabf98..fe22fed74c 100644 --- a/test/integration/api.bats +++ b/test/integration/api.bats @@ -955,14 +955,13 @@ function teardown() { [ "${#lines[@]}" -ge 8 ] # verify - client_reg='^Client version: [0-9]+\.[0-9]+\.[0-9]+$' - server_reg='^Server version: swarm/[0-9]+\.[0-9]+\.[0-9]+$' + client_reg='^Client version: [0-9]+\.[0-9]+\.[0-9]+.*$' + server_reg='^Server version: swarm/[0-9]+\.[0-9]+\.[0-9]+.*$' [[ "${lines[0]}" =~ $client_reg ]] [[ "${lines[5]}" =~ $server_reg ]] } @test "docker wait" { - TEMP_FILE=$(mktemp) start_docker 3 swarm_manage @@ -977,11 +976,8 @@ function teardown() { [[ "${lines[1]}" == *"Up"* ]] # wait until exist(after 1 seconds) - timeout 5 docker -H $SWARM_HOST wait test_container > $TEMP_FILE + run timeout 5 docker -H $SWARM_HOST wait test_container - run cat $TEMP_FILE [ "${#lines[@]}" -eq 1 ] [[ "${output}" == "0" ]] - - rm -f $TEMP_FILE }