Add a bunch more tweaks to the parallel test compilation
- put all the precompiled test binaries in $DEST so they show up in bundles and can be re-run individually afterwards - support cases where parallel is not installed (when using dyntest-unit, for example, this is much more common, since it's designed to be run outside the Dockerfile) - use "mktemp -d" instead of "/tmp" directly for our temporary parallel HOME - update the default PARALLEL_JOBS to be the value of "nproc" instead of 0, since "0 means as many as possible" (see https://www.gnu.org/software/parallel/man.html#jobs_n) Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon) Upstream-commit: a6085fd430e8f155e4a0738de752df3c77bc132f Component: engine
This commit is contained in:
@ -2,11 +2,11 @@
|
||||
set -e
|
||||
|
||||
DEST=$1
|
||||
: ${PARALLEL_JOBS:=$(nproc)}
|
||||
|
||||
RED=$'\033[31m'
|
||||
GREEN=$'\033[32m'
|
||||
TEXTRESET=$'\033[0m' # reset the foreground colour
|
||||
: ${PARALLEL_JOBS:=0}
|
||||
|
||||
# Run Docker's test suite, including sub-packages, and store their output as a bundle
|
||||
# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
|
||||
@ -23,10 +23,10 @@ bundle_test_unit() {
|
||||
TESTDIRS=$(find_dirs '*_test.go')
|
||||
fi
|
||||
|
||||
(
|
||||
if command -v parallel &> /dev/null; then (
|
||||
# accomodate parallel to be able to access variables
|
||||
export SHELL=/bin/bash
|
||||
export HOME=/tmp
|
||||
export SHELL="$BASH"
|
||||
export HOME="$(mktemp -d)"
|
||||
mkdir -p "$HOME/.parallel"
|
||||
touch "$HOME/.parallel/ignored_vars"
|
||||
export -f go_compile_test_dir
|
||||
@ -38,8 +38,15 @@ bundle_test_unit() {
|
||||
export BUILDFLAGS_FILE="$HOME/buildflags_file"
|
||||
( IFS=$'\n'; echo "${BUILDFLAGS[*]}" ) > "$BUILDFLAGS_FILE"
|
||||
|
||||
echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --env _ go_compile_test_dir | go_run_test_dir
|
||||
)
|
||||
echo "$TESTDIRS" | parallel --jobs "$PARALLEL_JOBS" --env _ go_compile_test_dir
|
||||
rm -rf "$HOME"
|
||||
) else
|
||||
# aww, no "parallel" available - fall back to boring
|
||||
for test_dir in $TESTDIRS; do
|
||||
go_compile_test_dir "$test_dir"
|
||||
done
|
||||
fi
|
||||
echo "$TESTDIRS" | go_run_test_dir
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,16 +55,13 @@ go_run_test_dir() {
|
||||
while read dir; do
|
||||
echo
|
||||
echo '+ go test' $TESTFLAGS "github.com/dotcloud/docker${dir#.}"
|
||||
pushd "$dir" > /dev/null
|
||||
t=$(basename "$dir").test
|
||||
if ! ./$t; then
|
||||
precompiled="$DEST/precompiled/$dir.test"
|
||||
if ! "$precompiled"; then
|
||||
TESTS_FAILED+=("$dir")
|
||||
echo
|
||||
echo "${RED}Tests failed: $dir${TEXTRESET}"
|
||||
sleep 1 # give it a second, so observers watching can take note
|
||||
fi
|
||||
rm ./$t || true
|
||||
popd > /dev/null
|
||||
done
|
||||
|
||||
echo
|
||||
|
||||
Reference in New Issue
Block a user