Browse code

Add support for repeating integration tests

`TEST_REPEAT=n` runs the test suite again n times or
until the first failure without doing building and
daemon setup. Useful for debugging flaky tests.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2016/03/27 14:56:45
Showing 2 changed files
... ...
@@ -27,6 +27,8 @@ export DOCKER_PKG='github.com/docker/docker'
27 27
 export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
28 28
 export MAKEDIR="$SCRIPTDIR/make"
29 29
 
30
+: ${TEST_REPEAT:=0}
31
+
30 32
 # We're a nice, sexy, little shell script, and people might try to run us;
31 33
 # but really, they shouldn't. We want to be in a container!
32 34
 inContainer="AssumeSoInitially"
... ...
@@ -229,18 +231,29 @@ go_test_dir() {
229 229
 	dir=$1
230 230
 	coverpkg=$2
231 231
 	testcover=()
232
+	testcoverprofile=()
233
+	testbinary="$DEST/test.main"
232 234
 	if [ "$HAVE_GO_TEST_COVER" ]; then
233 235
 		# if our current go install has -cover, we want to use it :)
234 236
 		mkdir -p "$DEST/coverprofiles"
235 237
 		coverprofile="docker${dir#.}"
236 238
 		coverprofile="$ABS_DEST/coverprofiles/${coverprofile//\//-}"
237
-		testcover=( -cover -coverprofile "$coverprofile" $coverpkg )
239
+		testcover=( -test.cover )
240
+		testcoverprofile=( -test.coverprofile "$coverprofile" $coverpkg )
238 241
 	fi
239 242
 	(
240 243
 		echo '+ go test' $TESTFLAGS "${DOCKER_PKG}${dir#.}"
241 244
 		cd "$dir"
242 245
 		export DEST="$ABS_DEST" # we're in a subshell, so this is safe -- our integration-cli tests need DEST, and "cd" screws it up
243
-		test_env go test ${testcover[@]} -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS
246
+		go test -c -o "$testbinary" ${testcover[@]} -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}"
247
+		i=0
248
+		while ((++i)); do
249
+			test_env "$testbinary" ${testcoverprofile[@]} $TESTFLAGS
250
+			if [ $i -gt "$TEST_REPEAT" ]; then
251
+				break
252
+			fi
253
+			echo "Repeating test ($i)"
254
+		done
244 255
 	)
245 256
 }
246 257
 test_env() {
247 258
old mode 100644
248 259
new mode 100755
... ...
@@ -2,7 +2,7 @@
2 2
 set -e
3 3
 
4 4
 bundle_test_integration_cli() {
5
-	TESTFLAGS="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -timeout=360m"
5
+	TESTFLAGS="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -test.timeout=360m"
6 6
 	go_test_dir ./integration-cli
7 7
 }
8 8