From 9fce47ac680770c58a51124555ff1a99c6a5908d Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Wed, 27 Aug 2014 09:22:01 -0700 Subject: [PATCH] Add the ability to multiple test iterations without rebuilding. Address comments. --- hack/test-go.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/hack/test-go.sh b/hack/test-go.sh index c4b4085e9b5..378e96708ab 100755 --- a/hack/test-go.sh +++ b/hack/test-go.sh @@ -47,9 +47,54 @@ KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout 30s} cd "${KUBE_TARGET}" -if [ "$1" != "" ]; then - go test -race $KUBE_TIMEOUT $KUBE_COVER -coverprofile=tmp.out "$KUBE_GO_PACKAGE/$1" "${@:2}" +while getopts "i:" opt ; do + case $opt in + i) + iterations=$OPTARG + ;; + ?) + echo "Invalid argument -$OPTARG" + exit 1 + ;; + :) + echo "Option -$OPTARG " + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +if [[ -n "${iterations}" ]]; then + echo "Running ${iterations} times" + if [[ -n "$1" ]]; then + pkg=$KUBE_GO_PACKAGE/$1 + fi + rm -f *.test + # build a test binary + echo "${pkg}" + go test -c -race ${KUBE_TIMEOUT} "${pkg}" + # keep going, even if there are failures + pass=0 + count=0 + for i in $(seq 1 ${iterations}); do + for test_binary in *.test; do + if "./${test_binary}"; then + ((pass++)) + fi + ((count++)) + done + done 2>&1 + echo "${pass}" / "${count}" passing + if [[ ${pass} != ${count} ]]; then + exit 1 + else + exit 0 + fi +fi + +if [[ -n "$1" ]]; then + go test -race ${KUBE_TIMEOUT} ${KUBE_COVER} -coverprofile=tmp.out "${KUBE_GO_PACKAGE}/$1" "${@:2}" exit 0 fi -find_test_dirs | xargs go test -race -timeout 30s $KUBE_COVER "${@:2}" +find_test_dirs | xargs go test -race -timeout 30s ${KUBE_COVER} "${@:2}"