Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -18,6 +18,9 @@ if ! docker inspect -t image emptyfs &> /dev/null; then |
| 18 | 18 |
tar -cf layer.tar --files-from /dev/null |
| 19 | 19 |
) |
| 20 | 20 |
) |
| 21 |
- ( set -x; tar -cC "$dir" . | docker load ) |
|
| 21 |
+ ( |
|
| 22 |
+ [ -n "$TESTDEBUG" ] && set -x |
|
| 23 |
+ tar -cC "$dir" . | docker load |
|
| 24 |
+ ) |
|
| 22 | 25 |
rm -rf "$dir" |
| 23 | 26 |
fi |
| ... | ... |
@@ -76,24 +76,26 @@ if [ -z "$DOCKER_TEST_HOST" ]; then |
| 76 | 76 |
# see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16 |
| 77 | 77 |
export container="" |
| 78 | 78 |
( |
| 79 |
- set -x |
|
| 79 |
+ [ -n "$TESTDEBUG" ] && set -x |
|
| 80 | 80 |
/etc/init.d/apparmor start |
| 81 | 81 |
) |
| 82 | 82 |
fi |
| 83 | 83 |
|
| 84 |
- export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one |
|
| 85 |
- ( set -x; exec \ |
|
| 86 |
- dockerd --debug \ |
|
| 87 |
- --host "$DOCKER_HOST" \ |
|
| 88 |
- --storage-driver "$DOCKER_GRAPHDRIVER" \ |
|
| 89 |
- --pidfile "$DEST/docker.pid" \ |
|
| 90 |
- --userland-proxy="$DOCKER_USERLANDPROXY" \ |
|
| 91 |
- $storage_params \ |
|
| 92 |
- $extra_params \ |
|
| 93 |
- &> "$DEST/docker.log" |
|
| 84 |
+ # "pwd" tricks to make sure $DEST is an absolute path, not a relative one |
|
| 85 |
+ export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" |
|
| 86 |
+ ( |
|
| 87 |
+ echo "Starting dockerd" |
|
| 88 |
+ [ -n "$TESTDEBUG" ] && set -x |
|
| 89 |
+ exec \ |
|
| 90 |
+ dockerd --debug \ |
|
| 91 |
+ --host "$DOCKER_HOST" \ |
|
| 92 |
+ --storage-driver "$DOCKER_GRAPHDRIVER" \ |
|
| 93 |
+ --pidfile "$DEST/docker.pid" \ |
|
| 94 |
+ --userland-proxy="$DOCKER_USERLANDPROXY" \ |
|
| 95 |
+ $storage_params \ |
|
| 96 |
+ $extra_params \ |
|
| 97 |
+ &> "$DEST/docker.log" |
|
| 94 | 98 |
) & |
| 95 |
- # make sure that if the script exits unexpectedly, we stop this daemon we just started |
|
| 96 |
- trap 'bundle .integration-daemon-stop' EXIT |
|
| 97 | 99 |
else |
| 98 | 100 |
export DOCKER_HOST="$DOCKER_TEST_HOST" |
| 99 | 101 |
fi |
| ... | ... |
@@ -1,11 +1,12 @@ |
| 1 | 1 |
#!/usr/bin/env bash |
| 2 | 2 |
|
| 3 | 3 |
if [ ! "$(go env GOOS)" = 'windows' ]; then |
| 4 |
- trap - EXIT # reset EXIT trap applied in .integration-daemon-start |
|
| 5 |
- |
|
| 6 | 4 |
for pidFile in $(find "$DEST" -name docker.pid); do |
| 7 |
- pid=$(set -x; cat "$pidFile") |
|
| 8 |
- ( set -x; kill "$pid" ) |
|
| 5 |
+ pid=$([ -n "$TESTDEBUG" ] && set -x; cat "$pidFile") |
|
| 6 |
+ ( |
|
| 7 |
+ [ -n "$TESTDEBUG" ] && set -x |
|
| 8 |
+ kill "$pid" |
|
| 9 |
+ ) |
|
| 9 | 10 |
if ! wait "$pid"; then |
| 10 | 11 |
echo >&2 "warning: PID $pid from $pidFile had a nonzero exit code" |
| 11 | 12 |
fi |
| ... | ... |
@@ -15,7 +16,7 @@ if [ ! "$(go env GOOS)" = 'windows' ]; then |
| 15 | 15 |
# Stop apparmor if it is enabled |
| 16 | 16 |
if [ -e "/sys/module/apparmor/parameters/enabled" ] && [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then |
| 17 | 17 |
( |
| 18 |
- set -x |
|
| 18 |
+ [ -n "$TESTDEBUG" ] && set -x |
|
| 19 | 19 |
/etc/init.d/apparmor stop |
| 20 | 20 |
) |
| 21 | 21 |
fi |
| ... | ... |
@@ -1,26 +1,38 @@ |
| 1 | 1 |
#!/usr/bin/env bash |
| 2 |
+# |
|
| 3 |
+# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want |
|
| 4 |
+# to run certain tests on your local host, you should run with command: |
|
| 5 |
+# |
|
| 6 |
+# TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration |
|
| 7 |
+# |
|
| 2 | 8 |
|
| 3 | 9 |
source "$SCRIPTDIR/make/.go-autogen" |
| 4 | 10 |
|
| 5 |
-: ${TEST_REPEAT:=0}
|
|
| 11 |
+: ${TEST_REPEAT:=1}
|
|
| 12 |
+ |
|
| 13 |
+integration_api_dirs=("$(find ./integration -type d | grep -vE '^./integration$')")
|
|
| 14 |
+ |
|
| 15 |
+run_test_integration() {
|
|
| 16 |
+ local flags="-test.v -test.timeout=${TIMEOUT} $TESTFLAGS"
|
|
| 17 |
+ for dir in $integration_api_dirs; do |
|
| 18 |
+ ( |
|
| 19 |
+ cd $dir |
|
| 20 |
+ echo "Running $PWD" |
|
| 21 |
+ test_env ./test.main $flags |
|
| 22 |
+ ) |
|
| 23 |
+ done |
|
| 6 | 24 |
|
| 7 |
-bundle_test_integration() {
|
|
| 8 |
- ( |
|
| 9 |
- local flags="-v -test.timeout=${TIMEOUT} $TESTFLAGS"
|
|
| 10 |
- cd integration |
|
| 11 |
- set -ex |
|
| 12 |
- # TODO: run existing binary? |
|
| 13 |
- go test -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $flags ./...
|
|
| 14 |
- ) |
|
| 15 | 25 |
( |
| 16 |
- local flags="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -test.timeout=360m"
|
|
| 17 |
- go_test_dir integration-cli |
|
| 26 |
+ flags="-check.v -check.timeout=${TIMEOUT} -test.timeout=360m $TESTFLAGS"
|
|
| 27 |
+ cd integration-cli > /dev/null |
|
| 28 |
+ echo "Running $PWD" |
|
| 29 |
+ test_env ./test.main $flags |
|
| 18 | 30 |
) |
| 19 | 31 |
} |
| 20 | 32 |
|
| 21 | 33 |
build_test_suite_binaries() {
|
| 22 |
- build_test_suite_binary integration-cli "test.main" |
|
| 23 |
- for dir in $(find integration -type d); do |
|
| 34 |
+ build_test_suite_binary ./integration-cli "test.main" |
|
| 35 |
+ for dir in $integration_api_dirs; do |
|
| 24 | 36 |
build_test_suite_binary "$dir" "test.main" |
| 25 | 37 |
done |
| 26 | 38 |
} |
| ... | ... |
@@ -30,39 +42,29 @@ build_test_suite_binary() {
|
| 30 | 30 |
local dir="$1" |
| 31 | 31 |
local out="$2" |
| 32 | 32 |
echo Building test suite binary "$dir/$out" |
| 33 |
- go test -c -o "$dir/$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" "./$dir"
|
|
| 33 |
+ go test -c -o "$dir/$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" "$dir"
|
|
| 34 | 34 |
} |
| 35 | 35 |
|
| 36 |
-# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. |
|
| 37 |
-# You can use this to select certain tests to run, e.g. |
|
| 38 |
-# |
|
| 39 |
-# TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit |
|
| 40 |
-# |
|
| 41 |
-# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want |
|
| 42 |
-# to run certain tests on your local host, you should run with command: |
|
| 43 |
-# |
|
| 44 |
-# TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration |
|
| 45 |
-# |
|
| 46 |
-go_test_dir() {
|
|
| 47 |
- local dir=$1 |
|
| 48 |
- ( |
|
| 49 |
- set -e |
|
| 50 |
- # DEST is used by the test suite |
|
| 51 |
- export DEST="$ABS_DEST" |
|
| 52 |
- cd "$dir" |
|
| 53 |
- for i in $(seq 0 $TEST_REPEAT); do |
|
| 54 |
- echo "Repeating integration-test ($i)" |
|
| 55 |
- test_env "./test.main" $TESTFLAGS |
|
| 56 |
- done |
|
| 57 |
- ) |
|
| 36 |
+cleanup_test_suite_binaries() {
|
|
| 37 |
+ [ -n "$TESTDEBUG" ] && return |
|
| 38 |
+ echo "Removing test suite binaries" |
|
| 39 |
+ find integration* -name test.main | xargs -r rm |
|
| 58 | 40 |
} |
| 59 | 41 |
|
| 42 |
+repeat() {
|
|
| 43 |
+ for i in $(seq 1 $TEST_REPEAT); do |
|
| 44 |
+ echo "Running integration-test (iteration $i)" |
|
| 45 |
+ $@ |
|
| 46 |
+ done |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 49 |
+# use "env -i" to tightly control the environment variables that bleed into the tests |
|
| 60 | 50 |
test_env() {
|
| 61 | 51 |
( |
| 62 |
- set -xe |
|
| 63 |
- # use "env -i" to tightly control the environment variables that bleed into the tests |
|
| 52 |
+ set -e |
|
| 53 |
+ [ -n "$TESTDEBUG" ] && set -x |
|
| 64 | 54 |
env -i \ |
| 65 |
- DEST="$DEST" \ |
|
| 55 |
+ DEST="$ABS_DEST" \ |
|
| 66 | 56 |
DOCKER_CLI_VERSION="$DOCKER_CLI_VERSION" \ |
| 67 | 57 |
DOCKER_API_VERSION="$DOCKER_API_VERSION" \ |
| 68 | 58 |
DOCKER_INTEGRATION_DAEMON_DEST="$DOCKER_INTEGRATION_DAEMON_DEST" \ |
| ... | ... |
@@ -85,3 +87,19 @@ test_env() {
|
| 85 | 85 |
"$@" |
| 86 | 86 |
) |
| 87 | 87 |
} |
| 88 |
+ |
|
| 89 |
+ |
|
| 90 |
+error_on_leaked_containerd_shims() {
|
|
| 91 |
+ if [ "$(go env GOOS)" == 'windows' ]; then |
|
| 92 |
+ return |
|
| 93 |
+ fi |
|
| 94 |
+ |
|
| 95 |
+ leftovers=$(ps -ax -o pid,cmd | |
|
| 96 |
+ awk '$2 == "docker-containerd-shim" && $4 ~ /.*\/bundles\/.*\/test-integration/ { print $1 }')
|
|
| 97 |
+ if [ -n "$leftovers" ]; then |
|
| 98 |
+ ps aux |
|
| 99 |
+ kill -9 $leftovers 2> /dev/null |
|
| 100 |
+ echo "!!!! WARNING you have left over shim(s), Cleanup your test !!!!" |
|
| 101 |
+ exit 1 |
|
| 102 |
+ fi |
|
| 103 |
+} |
| ... | ... |
@@ -4,28 +4,19 @@ set -e |
| 4 | 4 |
source "${MAKEDIR}/.go-autogen"
|
| 5 | 5 |
source hack/make/.integration-test-helpers |
| 6 | 6 |
|
| 7 |
-# subshell so that we can export PATH without breaking other things |
|
| 8 | 7 |
( |
| 9 |
- build_test_suite_binaries |
|
| 10 |
- |
|
| 8 |
+ build_test_suite_binaries |
|
| 11 | 9 |
bundle .integration-daemon-start |
| 12 |
- |
|
| 13 | 10 |
bundle .integration-daemon-setup |
| 14 | 11 |
|
| 15 |
- bundle_test_integration |
|
| 12 |
+ local testexit=0 |
|
| 13 |
+ ( repeat run_test_integration ) || testexit=$? |
|
| 16 | 14 |
|
| 15 |
+ # Always run cleanup, even if the subshell fails |
|
| 17 | 16 |
bundle .integration-daemon-stop |
| 17 |
+ cleanup_test_suite_binaries |
|
| 18 |
+ error_on_leaked_containerd_shims |
|
| 18 | 19 |
|
| 19 |
- if [ "$(go env GOOS)" != 'windows' ] |
|
| 20 |
- then |
|
| 21 |
- leftovers=$(ps -ax -o pid,cmd | awk '$2 == "docker-containerd-shim" && $4 ~ /.*\/bundles\/.*\/test-integration/ { print $1 }')
|
|
| 22 |
- if [ -n "$leftovers" ] |
|
| 23 |
- then |
|
| 24 |
- ps aux |
|
| 25 |
- kill -9 $leftovers 2> /dev/null |
|
| 26 |
- echo "!!!! WARNING you have left over shim(s), Cleanup your test !!!!" |
|
| 27 |
- exit 1 |
|
| 28 |
- fi |
|
| 29 |
- fi |
|
| 20 |
+ exit $testexit |
|
| 30 | 21 |
|
| 31 | 22 |
) 2>&1 | tee -a "$DEST/test.log" |