test/*: clean up semaphore scripts

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee
2018-04-10 23:25:24 -07:00
parent cdbb8ffdc1
commit a28cf17f25
3 changed files with 174 additions and 99 deletions

View File

@@ -118,7 +118,7 @@ compile-setup-gopath-with-docker-test:
#
# Local machine:
# TEST_OPTS="PASSES='fmt'" make test
# TEST_OPTS="PASSES='fmt bom dep compile build unit'" make test
# TEST_OPTS="PASSES='fmt bom dep build unit'" make test
# TEST_OPTS="PASSES='build unit release integration_e2e functional'" make test
# TEST_OPTS="PASSES='build grpcproxy'" make test
#
@@ -128,7 +128,7 @@ compile-setup-gopath-with-docker-test:
# TEST_OPTS="VERBOSE=2 PASSES='unit'" make docker-test
#
# Travis CI (test with docker):
# TEST_OPTS="PASSES='fmt bom dep compile build unit'" make docker-test
# TEST_OPTS="PASSES='fmt bom dep build unit'" make docker-test
#
# Semaphore CI (test with docker):
# TEST_OPTS="PASSES='build unit release integration_e2e functional'" make docker-test

257
test
View File

@@ -4,46 +4,70 @@
# ./test
# ./test -v
#
# Run tests for one package
#
# PKG=./wal ./test
# PKG=snap ./test
# Run specified test pass
#
# $ PASSES=unit ./test
# $ PASSES=integration ./test
#
#
# Run tests for one package
# Each pass has different default timeout, if you just run tests in one package or 1 test case then you can set TIMEOUT
# flag for different expectation
#
# $ PASSES=unit PKG=./wal TIMEOUT=1m ./test
# $ PASSES=integration PKG=client/integration TIMEOUT=1m ./test
#
#
# Run specified unit tests in one package
# To run all the tests with prefix of "TestNew", set "TESTCASE=TestNew ";
# to run only "TestNew", set "TESTCASE="\bTestNew\b""
#
# $ PASSES=unit PKG=./wal TESTCASE=TestNew TIMEOUT=1m ./test
# $ PASSES=unit PKG=./wal TESTCASE="\bTestNew\b" TIMEOUT=1m ./test
# $ PASSES=integration PKG=client/integration TESTCASE="\bTestV2NoRetryEOF\b" TIMEOUT=1m ./test
#
#
# Run code coverage
# COVERDIR must either be a absolute path or a relative path to the etcd root
# COVERDIR=coverage PASSES="build_cov cov" ./test
# $ COVERDIR=coverage PASSES="build_cov cov" ./test
set -e
source ./build
# build before setting up test GOPATH
if [[ "${PASSES}" == *"functional"* ]]; then
./tools/functional-tester/build
./functional/build
fi
# build tests with vendored dependencies
etcd_setup_gopath
if [ -z "$PASSES" ]; then
PASSES="fmt bom dep compile build unit"
PASSES="fmt bom dep build unit"
fi
USERPKG=${PKG:-}
# Invoke ./cover for HTML output
# Invoke ./tests/cover.test.bash for HTML output
COVER=${COVER:-"-cover"}
# Hack: gofmt ./ will recursively check the .git directory. So use *.go for gofmt.
IGNORE_PKGS="(cmd/|etcdserverpb|rafttest|gopath.proto|v3lockpb|v3electionpb)"
INTEGRATION_PKGS="(integration|e2e|contrib|functional-tester)"
INTEGRATION_PKGS="(integration|e2e|contrib|functional)"
# all github.com/coreos/etcd/whatever pkgs that are not auto-generated / tools
# shellcheck disable=SC1117
PKGS=$(find . -name \*.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | grep -vE "(tools/|contrib/|e2e|pb)" | sed "s|\.|${REPO_PATH}|g" | xargs echo)
# pkg1,pkg2,pkg3
PKGS_COMMA=${PKGS// /,}
# shellcheck disable=SC1117
TEST_PKGS=$(find . -name \*_test.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
# shellcheck disable=SC1117
FORMATTABLE=$(find . -name \*.go | while read -r a; do echo "$(dirname "$a")/*.go"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
TESTABLE_AND_FORMATTABLE=$(echo "$TEST_PKGS" | grep -vE "$INTEGRATION_PKGS")
# check if user provided PKG override
@@ -58,17 +82,22 @@ else
# only run gofmt on packages provided by user
FMT="$TEST"
fi
# shellcheck disable=SC2206
FMT=($FMT)
# prepend REPO_PATH to each local package
split=$TEST
TEST=""
for a in $split; do TEST="$TEST ${REPO_PATH}/${a}"; done
# shellcheck disable=SC2206
TEST=($TEST)
# TODO: 'client' pkg fails with gosimple from generated files
# TODO: 'rafttest' is failing with unused
STATIC_ANALYSIS_PATHS=$(find . -name \*.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | grep -v 'client')
# shellcheck disable=SC2206
STATIC_ANALYSIS_PATHS=($STATIC_ANALYSIS_PATHS)
if [ -z "$GOARCH" ]; then
@@ -80,6 +109,11 @@ if [ "$GOARCH" == "amd64" ]; then
RACE="--race"
fi
RUN_ARG=""
if [ ! -z "${TESTCASE}" ]; then
RUN_ARG="-run=${TESTCASE}"
fi
function unit_pass {
echo "Running unit tests..."
GO_TEST_FLAG=""
@@ -90,31 +124,69 @@ function unit_pass {
GO_TEST_FLAG="-v"
export CLIENT_DEBUG=1
fi
# only -run=Test so examples can run in integration tests
go test ${GO_TEST_FLAG} -timeout 3m "${COVER}" ${RACE} -cpu 1,2,4 -run=Test "$@" "${TEST[@]}"
if [ "${RUN_ARG}" == "" ]; then
RUN_ARG="-run=Test"
fi
# check if user provided time out, especially useful when just run one test case
# expectation could be different
USERTIMEOUT=""
if [ -z "${TIMEOUT}" ]; then
USERTIMEOUT="3m"
else
USERTIMEOUT="${TIMEOUT}"
fi
go test ${GO_TEST_FLAG} -timeout "${USERTIMEOUT}" "${COVER}" ${RACE} -cpu 1,2,4 ${RUN_ARG} "$@" "${TEST[@]}"
}
function integration_pass {
echo "Running integration tests..."
go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/integration"
integration_extra "$@"
# check if user provided time out, especially useful when just run one test case
# expectation could be different
USERTIMEOUT=""
if [ -z "${TIMEOUT}" ]; then
USERTIMEOUT="20m"
else
USERTIMEOUT="${TIMEOUT}"
fi
# if TESTCASE and PKG set, run specified test case in specified PKG
# if TESTCASE set, PKG not set, run specified test case in all integration and integration_extra packages
# if TESTCASE not set, PKG set, run all test cases in specified package
# if TESTCASE not set, PKG not set, run all tests in all integration and integration_extra packages
if [ -z "${TESTCASE}" ] && [ -z "${USERPKG}" ]; then
go test -timeout "${USERTIMEOUT}" -v -cpu 1,2,4 "$@" "${REPO_PATH}/integration"
integration_extra "$@"
else
if [ -z "${USERPKG}" ]; then
INTEGTESTPKG=("${REPO_PATH}/integration"
"${REPO_PATH}/client/integration"
"${REPO_PATH}/clientv3/integration"
"${REPO_PATH}/contrib/raftexample"
"${REPO_PATH}/store")
else
INTEGTESTPKG=("${TEST[@]}")
fi
go test -timeout "${USERTIMEOUT}" -v -cpu 1,2,4 "${RUN_ARG}" "$@" "${INTEGTESTPKG[@]}"
fi
}
function integration_extra {
go test -timeout 1m -v ${RACE} -cpu 1,2,4 "$@" "${REPO_PATH}/client/integration"
go test -timeout 20m -v ${RACE} -cpu 1,2,4 "$@" "${REPO_PATH}/clientv3/integration"
go test -timeout 25m -v ${RACE} -cpu 1,2,4 "$@" "${REPO_PATH}/clientv3/integration"
go test -timeout 1m -v -cpu 1,2,4 "$@" "${REPO_PATH}/contrib/raftexample"
go test -timeout 5m -v ${RACE} -tags v2v3 "$@" "${REPO_PATH}/store"
go test -timeout 5m -v ${RACE} -tags v2v3 "$@" "${REPO_PATH}/etcdserver/v2store"
go test -timeout 1m -v ${RACE} -cpu 1,2,4 -run=Example "$@" "${TEST[@]}"
}
function functional_pass {
# Clean up any data and logs from previous runs
rm -rf ./agent-*
rm -rf /tmp/etcd-agent-data-*
for a in 1 2 3; do
mkdir -p ./agent-$a
./bin/etcd-agent -etcd-path ./bin/etcd -etcd-log-dir "./agent-$a" -port ":${a}9027" &
./bin/etcd-agent --network tcp --address 127.0.0.1:${a}9027 &
pid="$!"
agent_pids="${agent_pids} $pid"
done
@@ -126,31 +198,20 @@ function functional_pass {
done
done
echo "Starting 'etcd-tester'"
./bin/etcd-tester \
-agent-endpoints "127.0.0.1:19027,127.0.0.1:29027,127.0.0.1:39027" \
-client-ports 1379,2379,3379 \
-advertise-client-ports 13790,23790,33790 \
-peer-ports 1380,2380,3380 \
-advertise-peer-ports 13800,23800,33800 \
-limit 1 \
-schedule-cases "0 1 2 3 4 5 6 7 8 9" \
-stress-qps 1000 \
-stress-key-txn-count 100 \
-stress-key-txn-ops 10 \
-exit-on-failure && echo "'etcd-tester' succeeded"
echo "functional test START!"
./bin/etcd-tester --config ./functional.yaml && echo "'etcd-tester' succeeded"
ETCD_TESTER_EXIT_CODE=$?
echo "ETCD_TESTER_EXIT_CODE:" ${ETCD_TESTER_EXIT_CODE}
echo "Waiting for processes to exit"
# shellcheck disable=SC2206
agent_pids=($agent_pids)
kill -s TERM "${agent_pids[@]}"
for a in "${agent_pids[@]}"; do wait "$a" || true; done
kill -s TERM "${agent_pids[@]}" || true
if [[ "${ETCD_TESTER_EXIT_CODE}" -ne "0" ]]; then
echo "--- FAIL: exit code" ${ETCD_TESTER_EXIT_CODE}
exit ${ETCD_TESTER_EXIT_CODE}
fi
echo "functional test PASS!"
}
function cov_pass {
@@ -175,10 +236,11 @@ function cov_pass {
mkdir -p "$COVERDIR"
# run code coverage for unit and integration tests
GOCOVFLAGS="-covermode=set -coverpkg ${PKGS_COMMA} -v -timeout 15m"
GOCOVFLAGS="-covermode=set -coverpkg ${PKGS_COMMA} -v -timeout 20m"
# shellcheck disable=SC2206
GOCOVFLAGS=($GOCOVFLAGS)
failed=""
for t in $(echo "${TEST_PKGS}" | grep -vE "(e2e|functional-tester)"); do
for t in $(echo "${TEST_PKGS}" | grep -vE "(e2e|functional)"); do
tf=$(echo "$t" | tr / _)
# cache package compilation data for faster repeated builds
go test "${GOCOVFLAGS[@]}" -i "${REPO_PATH}/$t" || true
@@ -227,15 +289,25 @@ function cov_pass {
function e2e_pass {
echo "Running e2e tests..."
go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/e2e"
# check if user provided time out, especially useful when just run one test case
# expectation could be different
USERTIMEOUT=""
if [ -z "${TIMEOUT}" ]; then
USERTIMEOUT="20m"
else
USERTIMEOUT="${TIMEOUT}"
fi
go test -timeout "${USERTIMEOUT}" -v -cpu 1,2,4 "${RUN_ARG}" "$@" "${REPO_PATH}/e2e"
}
function integration_e2e_pass {
echo "Running integration and e2e tests..."
go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/e2e" &
go test -timeout 20m -v -cpu 1,2,4 "$@" "${REPO_PATH}/e2e" &
e2epid="$!"
go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/integration" &
go test -timeout 20m -v -cpu 1,2,4 "$@" "${REPO_PATH}/integration" &
intpid="$!"
wait $e2epid
wait $intpid
@@ -245,7 +317,7 @@ function integration_e2e_pass {
function grpcproxy_pass {
go test -timeout 20m -v ${RACE} -tags cluster_proxy -cpu 1,2,4 "$@" "${REPO_PATH}/integration"
go test -timeout 20m -v ${RACE} -tags cluster_proxy -cpu 1,2,4 "$@" "${REPO_PATH}/clientv3/integration"
go test -timeout 15m -v -tags cluster_proxy "$@" "${REPO_PATH}/e2e"
go test -timeout 20m -v -tags cluster_proxy "$@" "${REPO_PATH}/e2e"
}
function release_pass {
@@ -280,37 +352,11 @@ function release_pass {
mv /tmp/etcd ./bin/etcd-last-release
}
function gofmt_pass {
fmtRes=$(gofmt -l -s -d "${FMT[@]}")
if [ -n "${fmtRes}" ]; then
echo -e "gofmt checking failed:\n${fmtRes}"
exit 255
fi
}
function govet_pass {
vetRes=$(go vet "${TEST[@]}")
if [ -n "${vetRes}" ]; then
echo -e "govet checking failed:\n${vetRes}"
exit 255
fi
}
function govet_shadow_pass {
fmtpkgs=$(for a in "${FMT[@]}"; do dirname "$a"; done | sort | uniq | grep -v "\\.")
fmtpkgs=($fmtpkgs)
vetRes=$(go tool vet -all -shadow "${fmtpkgs[@]}" 2>&1 | grep -v '/gw/' || true)
if [ -n "${vetRes}" ]; then
echo -e "govet -all -shadow checking failed:\n${vetRes}"
exit 255
fi
}
function shellcheck_pass {
if which shellcheck >/dev/null; then
shellcheckResult=$(shellcheck -fgcc build test scripts/* 2>&1 || true)
shellcheckResult=$(shellcheck -fgcc build test scripts/*.sh 2>&1 || true)
if [ -n "${shellcheckResult}" ]; then
echo -e "shellcheck checking failed:\n${shellcheckResult}"
echo -e "shellcheck checking failed:\\n${shellcheckResult}"
exit 255
fi
fi
@@ -320,7 +366,7 @@ function markdown_you_pass {
# eschew you
yous=$(find . -name \*.md -exec grep -E --color "[Yy]ou[r]?[ '.,;]" {} + | grep -v /v2/ || true)
if [ ! -z "$yous" ]; then
echo -e "found 'you' in documentation:\n${yous}"
echo -e "found 'you' in documentation:\\n${yous}"
exit 255
fi
}
@@ -330,7 +376,7 @@ function markdown_marker_pass {
if which marker >/dev/null; then
markerResult=$(marker --skip-http --root ./Documentation 2>&1 || true)
if [ -n "${markerResult}" ]; then
echo -e "marker checking failed:\n${markerResult}"
echo -e "marker checking failed:\\n${markerResult}"
exit 255
fi
else
@@ -342,20 +388,23 @@ function goword_pass {
if which goword >/dev/null; then
# get all go files to process
gofiles=$(find "${FMT[@]}" -iname '*.go' 2>/dev/null)
# shellcheck disable=SC2206
gofiles_all=($gofiles)
# ignore tests and protobuf files
# shellcheck disable=SC1117
gofiles=$(echo "${gofiles_all[@]}" | sort | uniq | sed "s/ /\n/g" | grep -vE "(\\_test.go|\\.pb\\.go)")
# shellcheck disable=SC2206
gofiles=($gofiles)
# only check for broken exported godocs
gowordRes=$(goword -use-spell=false "${gofiles[@]}" | grep godoc-export | sort)
if [ ! -z "$gowordRes" ]; then
echo -e "goword checking failed:\n${gowordRes}"
echo -e "goword checking failed:\\n${gowordRes}"
exit 255
fi
# check some spelling
gowordRes=$(goword -ignore-file=.words clientv3/{*,*/*}.go 2>&1 | grep spell | sort)
if [ ! -z "$gowordRes" ]; then
echo -e "goword checking failed:\n${gowordRes}"
echo -e "goword checking failed:\\n${gowordRes}"
exit 255
fi
else
@@ -363,11 +412,38 @@ function goword_pass {
fi
}
function gofmt_pass {
fmtRes=$(gofmt -l -s -d "${FMT[@]}")
if [ -n "${fmtRes}" ]; then
echo -e "gofmt checking failed:\\n${fmtRes}"
exit 255
fi
}
function govet_pass {
vetRes=$(go vet "${TEST[@]}")
if [ -n "${vetRes}" ]; then
echo -e "govet checking failed:\\n${vetRes}"
exit 255
fi
}
function govet_shadow_pass {
fmtpkgs=$(for a in "${FMT[@]}"; do dirname "$a"; done | sort | uniq | grep -v "\\.")
# shellcheck disable=SC2206
fmtpkgs=($fmtpkgs)
vetRes=$(go tool vet -all -shadow "${fmtpkgs[@]}" 2>&1 | grep -v '/gw/' || true)
if [ -n "${vetRes}" ]; then
echo -e "govet -all -shadow checking failed:\\n${vetRes}"
exit 255
fi
}
function gosimple_pass {
if which gosimple >/dev/null; then
gosimpleResult=$(gosimple "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${gosimpleResult}" ]; then
echo -e "gosimple checking failed:\n${gosimpleResult}"
echo -e "gosimple checking failed:\\n${gosimpleResult}"
exit 255
fi
else
@@ -379,7 +455,7 @@ function unused_pass {
if which unused >/dev/null; then
unusedResult=$(unused "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${unusedResult}" ]; then
echo -e "unused checking failed:\n${unusedResult}"
echo -e "unused checking failed:\\n${unusedResult}"
exit 255
fi
else
@@ -395,11 +471,11 @@ function staticcheck_pass {
# See https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
STATIC_CHECK_MASK="SA(1012|1019|2002)"
if echo "${staticcheckResult}" | grep -vE "$STATIC_CHECK_MASK"; then
echo -e "staticcheck checking failed:\n${staticcheckResult}"
echo -e "staticcheck checking failed:\\n${staticcheckResult}"
exit 255
else
suppressed=$(echo "${staticcheckResult}" | sed 's/ /\n/g' | grep "(SA" | sort | uniq -c)
echo -e "staticcheck suppressed warnings:\n${suppressed}"
echo -e "staticcheck suppressed warnings:\\n${suppressed}"
fi
fi
else
@@ -411,7 +487,7 @@ function ineffassign_pass {
if which ineffassign >/dev/null; then
ineffassignResult=$(ineffassign "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${ineffassignResult}" ]; then
echo -e "ineffassign checking failed:\n${ineffassignResult}"
echo -e "ineffassign checking failed:\\n${ineffassignResult}"
exit 255
fi
else
@@ -423,7 +499,7 @@ function nakedret_pass {
if which nakedret >/dev/null; then
nakedretResult=$(nakedret "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${nakedretResult}" ]; then
echo -e "nakedret checking failed:\n${nakedretResult}"
echo -e "nakedret checking failed:\\n${nakedretResult}"
exit 255
fi
else
@@ -440,16 +516,18 @@ function license_header_pass {
fi
done
if [ -n "${licRes}" ]; then
echo -e "license header checking failed:\n${licRes}"
echo -e "license header checking failed:\\n${licRes}"
exit 255
fi
}
function receiver_name_pass {
# shellcheck disable=SC1117
recvs=$(grep 'func ([^*]' {*,*/*,*/*/*}.go | grep -Ev "(generated|pb/)" | tr ':' ' ' | \
awk ' { print $2" "$3" "$4" "$1 }' | sed "s/[a-zA-Z\.]*go//g" | sort | uniq | \
grep -Ev "(Descriptor|Proto|_)" | awk ' { print $3" "$4 } ' | sort | uniq -c | grep -v ' 1 ' | awk ' { print $2 } ')
if [ -n "${recvs}" ]; then
# shellcheck disable=SC2206
recvs=($recvs)
for recv in "${recvs[@]}"; do
echo "Mismatched receiver for $recv..."
@@ -475,7 +553,7 @@ function commit_title_pass {
spaceCommas=$(echo "$commitMsg" | sed 's/ /\n/g' | grep -c ',$' || echo 0)
commaSpaces=$(echo "$commitMsg" | sed 's/,/\n/g' | grep -c '^ ' || echo 0)
if [[ $(echo "$commitMsg" | grep -c ":..*") == 0 || "$commitMsg" == "$pkgPrefix" || "$spaceCommas" != "$commaSpaces" ]]; then
echo "$l"...
echo "$l"...
echo "Expected commit title format '<package>{\", \"<package>}: <description>'"
echo "Got: $l"
exit 255
@@ -486,13 +564,13 @@ function commit_title_pass {
function fmt_pass {
toggle_failpoints disable
for p in gofmt \
govet \
govet_shadow \
shellcheck \
for p in shellcheck \
markdown_you \
markdown_marker \
goword \
gofmt \
govet \
govet_shadow \
gosimple \
unused \
staticcheck \
@@ -502,9 +580,9 @@ function fmt_pass {
receiver_name \
commit_title \
; do
echo "Starting '$p' pass at $(date)"
echo "'$p' started at $(date)"
"${p}"_pass "$@"
echo "Finished '$p' pass at $(date)"
echo "'$p' completed at $(date)"
done
}
@@ -531,7 +609,7 @@ function dep_pass {
deps=$(go list -f '{{ .Deps }}' | sed 's/ /\n/g' | grep -E "${badpkg}" || echo "")
popd >/dev/null
if [ ! -z "$deps" ]; then
echo -e "clientv3 has masked dependencies:\n${deps}"
echo -e "clientv3 has masked dependencies:\\n${deps}"
exit 255
fi
}
@@ -543,14 +621,11 @@ function build_cov_pass {
go test -tags cov -c -covermode=set -coverpkg="$PKGS_COMMA" -o "${out}/etcdctl_test" "${REPO_PATH}/etcdctl"
}
function compile_pass {
echo "Checking build..."
go build -v ./tools/...
}
# fail fast on static tests
function build_pass {
echo "Checking build..."
GO_BUILD_FLAGS="-a -v" etcd_build
GO_BUILD_FLAGS="-a -v" tools_build
}
for pass in $PASSES; do

View File

@@ -7,15 +7,15 @@ fi
TEST_SUFFIX=$(date +%s | base64 | head -c 15)
TEST_OPTS="PASSES='build unit release integration_e2e functional' MANUAL_VER=v3.3.3"
TEST_OPTS="PASSES='build release e2e' MANUAL_VER=v3.3.3"
if [ "$TEST_ARCH" == "386" ]; then
TEST_OPTS="GOARCH=386 PASSES='build unit integration_e2e'"
TEST_OPTS="GOARCH=386 PASSES='build e2e'"
fi
docker run \
--rm \
--volume=`pwd`:/go/src/github.com/coreos/etcd \
gcr.io/etcd-development/etcd-test:go1.9.5 \
/bin/bash -c "${TEST_OPTS} ./test 2>&1 | tee test-${TEST_SUFFIX}.log"
--rm \
--volume=`pwd`:/go/src/github.com/coreos/etcd \
gcr.io/etcd-development/etcd-test:go1.9.5 \
/bin/bash -c "${TEST_OPTS} ./test 2>&1 | tee test-${TEST_SUFFIX}.log"
! egrep "(--- FAIL:|panic: test timed out|appears to have leaked)" -B50 -A10 test-${TEST_SUFFIX}.log