Cleanup test output, and binaries.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
de46fb736d
commit
4308e881cc
8 changed files with 94 additions and 77 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,7 +4,7 @@
|
|||
*.exe
|
||||
*.exe~
|
||||
*.orig
|
||||
*.test
|
||||
test.main
|
||||
.*.swp
|
||||
.DS_Store
|
||||
# a .bashrc may be added to customize the build environment
|
||||
|
|
|
@ -18,6 +18,9 @@ if ! docker inspect -t image emptyfs &> /dev/null; then
|
|||
tar -cf layer.tar --files-from /dev/null
|
||||
)
|
||||
)
|
||||
( set -x; tar -cC "$dir" . | docker load )
|
||||
(
|
||||
[ -n "$TESTDEBUG" ] && set -x
|
||||
tar -cC "$dir" . | docker load
|
||||
)
|
||||
rm -rf "$dir"
|
||||
fi
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
bundle .detect-daemon-osarch
|
||||
source "$MAKEDIR/.detect-daemon-osarch"
|
||||
if [ "$DOCKER_ENGINE_GOOS" != "windows" ]; then
|
||||
bundle .ensure-emptyfs
|
||||
fi
|
||||
|
|
|
@ -76,24 +76,26 @@ if [ -z "$DOCKER_TEST_HOST" ]; then
|
|||
# see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16
|
||||
export container=""
|
||||
(
|
||||
set -x
|
||||
[ -n "$TESTDEBUG" ] && set -x
|
||||
/etc/init.d/apparmor start
|
||||
)
|
||||
fi
|
||||
|
||||
export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one
|
||||
( set -x; exec \
|
||||
dockerd --debug \
|
||||
--host "$DOCKER_HOST" \
|
||||
--storage-driver "$DOCKER_GRAPHDRIVER" \
|
||||
--pidfile "$DEST/docker.pid" \
|
||||
--userland-proxy="$DOCKER_USERLANDPROXY" \
|
||||
$storage_params \
|
||||
$extra_params \
|
||||
&> "$DEST/docker.log"
|
||||
# "pwd" tricks to make sure $DEST is an absolute path, not a relative one
|
||||
export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock"
|
||||
(
|
||||
echo "Starting dockerd"
|
||||
[ -n "$TESTDEBUG" ] && set -x
|
||||
exec \
|
||||
dockerd --debug \
|
||||
--host "$DOCKER_HOST" \
|
||||
--storage-driver "$DOCKER_GRAPHDRIVER" \
|
||||
--pidfile "$DEST/docker.pid" \
|
||||
--userland-proxy="$DOCKER_USERLANDPROXY" \
|
||||
$storage_params \
|
||||
$extra_params \
|
||||
&> "$DEST/docker.log"
|
||||
) &
|
||||
# make sure that if the script exits unexpectedly, we stop this daemon we just started
|
||||
trap 'bundle .integration-daemon-stop' EXIT
|
||||
else
|
||||
export DOCKER_HOST="$DOCKER_TEST_HOST"
|
||||
fi
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ ! "$(go env GOOS)" = 'windows' ]; then
|
||||
trap - EXIT # reset EXIT trap applied in .integration-daemon-start
|
||||
|
||||
for pidFile in $(find "$DEST" -name docker.pid); do
|
||||
pid=$(set -x; cat "$pidFile")
|
||||
( set -x; kill "$pid" )
|
||||
pid=$([ -n "$TESTDEBUG" ] && set -x; cat "$pidFile")
|
||||
(
|
||||
[ -n "$TESTDEBUG" ] && set -x
|
||||
kill "$pid"
|
||||
)
|
||||
if ! wait "$pid"; then
|
||||
echo >&2 "warning: PID $pid from $pidFile had a nonzero exit code"
|
||||
fi
|
||||
|
@ -15,7 +16,7 @@ if [ ! "$(go env GOOS)" = 'windows' ]; then
|
|||
# Stop apparmor if it is enabled
|
||||
if [ -e "/sys/module/apparmor/parameters/enabled" ] && [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then
|
||||
(
|
||||
set -x
|
||||
[ -n "$TESTDEBUG" ] && set -x
|
||||
/etc/init.d/apparmor stop
|
||||
)
|
||||
fi
|
||||
|
|
|
@ -1,26 +1,38 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want
|
||||
# to run certain tests on your local host, you should run with command:
|
||||
#
|
||||
# TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration
|
||||
#
|
||||
|
||||
source "$SCRIPTDIR/make/.go-autogen"
|
||||
|
||||
: ${TEST_REPEAT:=0}
|
||||
: ${TEST_REPEAT:=1}
|
||||
|
||||
integration_api_dirs=("$(find ./integration -type d | grep -vE '^./integration$')")
|
||||
|
||||
run_test_integration() {
|
||||
local flags="-test.v -test.timeout=${TIMEOUT} $TESTFLAGS"
|
||||
for dir in $integration_api_dirs; do
|
||||
(
|
||||
cd $dir
|
||||
echo "Running $PWD"
|
||||
test_env ./test.main $flags
|
||||
)
|
||||
done
|
||||
|
||||
bundle_test_integration() {
|
||||
(
|
||||
local flags="-v -test.timeout=${TIMEOUT} $TESTFLAGS"
|
||||
cd integration
|
||||
set -ex
|
||||
# TODO: run existing binary?
|
||||
go test -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $flags ./...
|
||||
)
|
||||
(
|
||||
local flags="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -test.timeout=360m"
|
||||
go_test_dir integration-cli
|
||||
flags="-check.v -check.timeout=${TIMEOUT} -test.timeout=360m $TESTFLAGS"
|
||||
cd integration-cli > /dev/null
|
||||
echo "Running $PWD"
|
||||
test_env ./test.main $flags
|
||||
)
|
||||
}
|
||||
|
||||
build_test_suite_binaries() {
|
||||
build_test_suite_binary integration-cli "test.main"
|
||||
for dir in $(find integration -type d); do
|
||||
build_test_suite_binary ./integration-cli "test.main"
|
||||
for dir in $integration_api_dirs; do
|
||||
build_test_suite_binary "$dir" "test.main"
|
||||
done
|
||||
}
|
||||
|
@ -30,39 +42,29 @@ build_test_suite_binary() {
|
|||
local dir="$1"
|
||||
local out="$2"
|
||||
echo Building test suite binary "$dir/$out"
|
||||
go test -c -o "$dir/$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" "./$dir"
|
||||
go test -c -o "$dir/$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" "$dir"
|
||||
}
|
||||
|
||||
# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
|
||||
# You can use this to select certain tests to run, e.g.
|
||||
#
|
||||
# TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit
|
||||
#
|
||||
# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want
|
||||
# to run certain tests on your local host, you should run with command:
|
||||
#
|
||||
# TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration
|
||||
#
|
||||
go_test_dir() {
|
||||
local dir=$1
|
||||
(
|
||||
set -e
|
||||
# DEST is used by the test suite
|
||||
export DEST="$ABS_DEST"
|
||||
cd "$dir"
|
||||
for i in $(seq 0 $TEST_REPEAT); do
|
||||
echo "Repeating integration-test ($i)"
|
||||
test_env "./test.main" $TESTFLAGS
|
||||
done
|
||||
)
|
||||
cleanup_test_suite_binaries() {
|
||||
[ -n "$TESTDEBUG" ] && return
|
||||
echo "Removing test suite binaries"
|
||||
find integration* -name test.main | xargs -r rm
|
||||
}
|
||||
|
||||
repeat() {
|
||||
for i in $(seq 1 $TEST_REPEAT); do
|
||||
echo "Running integration-test (iteration $i)"
|
||||
$@
|
||||
done
|
||||
}
|
||||
|
||||
# use "env -i" to tightly control the environment variables that bleed into the tests
|
||||
test_env() {
|
||||
(
|
||||
set -xe
|
||||
# use "env -i" to tightly control the environment variables that bleed into the tests
|
||||
set -e
|
||||
[ -n "$TESTDEBUG" ] && set -x
|
||||
env -i \
|
||||
DEST="$DEST" \
|
||||
DEST="$ABS_DEST" \
|
||||
DOCKER_CLI_VERSION="$DOCKER_CLI_VERSION" \
|
||||
DOCKER_API_VERSION="$DOCKER_API_VERSION" \
|
||||
DOCKER_INTEGRATION_DAEMON_DEST="$DOCKER_INTEGRATION_DAEMON_DEST" \
|
||||
|
@ -85,3 +87,19 @@ test_env() {
|
|||
"$@"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
error_on_leaked_containerd_shims() {
|
||||
if [ "$(go env GOOS)" == 'windows' ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
leftovers=$(ps -ax -o pid,cmd |
|
||||
awk '$2 == "docker-containerd-shim" && $4 ~ /.*\/bundles\/.*\/test-integration/ { print $1 }')
|
||||
if [ -n "$leftovers" ]; then
|
||||
ps aux
|
||||
kill -9 $leftovers 2> /dev/null
|
||||
echo "!!!! WARNING you have left over shim(s), Cleanup your test !!!!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -4,28 +4,19 @@ set -e
|
|||
source "${MAKEDIR}/.go-autogen"
|
||||
source hack/make/.integration-test-helpers
|
||||
|
||||
# subshell so that we can export PATH without breaking other things
|
||||
(
|
||||
build_test_suite_binaries
|
||||
|
||||
build_test_suite_binaries
|
||||
bundle .integration-daemon-start
|
||||
|
||||
bundle .integration-daemon-setup
|
||||
|
||||
bundle_test_integration
|
||||
local testexit=0
|
||||
( repeat run_test_integration ) || testexit=$?
|
||||
|
||||
# Always run cleanup, even if the subshell fails
|
||||
bundle .integration-daemon-stop
|
||||
cleanup_test_suite_binaries
|
||||
error_on_leaked_containerd_shims
|
||||
|
||||
if [ "$(go env GOOS)" != 'windows' ]
|
||||
then
|
||||
leftovers=$(ps -ax -o pid,cmd | awk '$2 == "docker-containerd-shim" && $4 ~ /.*\/bundles\/.*\/test-integration/ { print $1 }')
|
||||
if [ -n "$leftovers" ]
|
||||
then
|
||||
ps aux
|
||||
kill -9 $leftovers 2> /dev/null
|
||||
echo "!!!! WARNING you have left over shim(s), Cleanup your test !!!!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
exit $testexit
|
||||
|
||||
) 2>&1 | tee -a "$DEST/test.log"
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
echo "WARNING: test-integration-cli is DEREPCATED. Use test-integration." >&2
|
||||
exit 1
|
||||
|
||||
# TODO: remove this and exit 1 once CI has changed to use test-integration
|
||||
bundle test-integration
|
||||
|
|
Loading…
Reference in a new issue