Various improvements to unit test running
- units.sh should exit on error. - Add race detector to unit test runner. - Use local testing/cover/cover tool in gen_coverage_report.sh and units.sh - Use the scheduler to parallelise the unit tests. - Make test run id a string and differentiate between unit runs and integration runs in the scheduler. - Pipe circle env vars through to build container so we can detect when to use the scheduler - Add python requests to the weave build container. - Quote test names in urls, make flask handle url segments with slashes in.
This commit is contained in:
1 parent
7aab5cc5b4
commit
13f1239a3e
12 files changed
+82
-33
No files matched your search
+46
-16
@@ -1,28 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
go get github.com/weaveworks/weave/testing/cover
|
||||
set -e
|
||||
|
||||
if [ -n "$COVERDIR" ] ; then
|
||||
coverdir="$COVERDIR"
|
||||
else
|
||||
coverdir=$(mktemp -d coverage.XXXXXXXXXX)
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SLOW=${SLOW-}
|
||||
GO_TEST_ARGS="-tags netgo -cpu 4"
|
||||
if [ -n "$SLOW" -o "$1" = "-slow" ]; then
|
||||
GO_TEST_ARGS="$GO_TEST_ARGS -race -covermode=atomic"
|
||||
|
||||
if [ -n "$COVERDIR" ] ; then
|
||||
coverdir="$COVERDIR"
|
||||
else
|
||||
coverdir=$(mktemp -d coverage.XXXXXXXXXX)
|
||||
fi
|
||||
|
||||
mkdir -p $coverdir
|
||||
fi
|
||||
|
||||
mkdir -p $coverdir
|
||||
fail=0
|
||||
|
||||
for dir in $(find . -type f -name '*_test.go' | xargs -n1 dirname | grep -v prog | sort -u); do
|
||||
go get -t -tags netgo $dir
|
||||
output=$(mktemp $coverdir/unit.XXXXXXXXXX)
|
||||
if ! go test -cpu 4 -tags netgo -covermode=count -coverprofile=$output $dir ; then
|
||||
fail=1
|
||||
fi
|
||||
TESTDIRS=$(find . -type f -name '*_test.go' | xargs -n1 dirname | grep -v prog | sort -u)
|
||||
|
||||
# If running on circle, use the scheduler to work out what tests to run on what shard
|
||||
if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" ]; then
|
||||
TESTDIRS=$(echo $TESTDIRS | "$DIR/sched" sched units-$CIRCLE_BUILD_NUM $CIRCLE_NODE_TOTAL $CIRCLE_NODE_INDEX)
|
||||
echo $TESTDIRS
|
||||
fi
|
||||
|
||||
for dir in $TESTDIRS; do
|
||||
|
||||
GO_TEST_ARGS_RUN="$GO_TEST_ARGS"
|
||||
if [ -n "$SLOW" ]; then
|
||||
go get -t -tags netgo $dir
|
||||
output=$(mktemp $coverdir/unit.XXXXXXXXXX)
|
||||
GO_TEST_ARGS_RUN="$GO_TEST_ARGS -coverprofile=$output"
|
||||
fi
|
||||
|
||||
START=$(date +%s)
|
||||
if ! go test $GO_TEST_ARGS_RUN $dir ; then
|
||||
fail=1
|
||||
fi
|
||||
RUNTIME=$(( $(date +%s) - $START ))
|
||||
|
||||
# Report test runtime when running on circle, to help scheduler
|
||||
if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" ]; then
|
||||
"$DIR/sched" time $dir $RUNTIME
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$COVERDIR" ] ; then
|
||||
cover $coverdir/* >profile.cov
|
||||
rm -rf $coverdir
|
||||
go tool cover -html=profile.cov -o=coverage.html
|
||||
if [ -n "$SLOW" -a -z "$COVERDIR" ] ; then
|
||||
$DIR/../testing/cover/cover $coverdir/* >profile.cov
|
||||
rm -rf $coverdir
|
||||
go tool cover -html=profile.cov -o=coverage.html
|
||||
go tool cover -func=profile.cov | tail -n1
|
||||
fi
|
||||
|
||||
exit $fail
|
||||
Reference in new issue
Block a user