vitess.io/vitess@v0.16.2/tools/e2e_test_race.sh (about) 1 #!/bin/bash 2 3 # Copyright 2019 The Vitess Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 source build.env 18 19 temp_log_file="$(mktemp --suffix .unit_test_race.log)" 20 trap '[ -f "$temp_log_file" ] && rm $temp_log_file' EXIT 21 22 # Wrapper around go test -race. 23 24 # This script exists because the -race test doesn't allow to distinguish 25 # between a failed (e.g. flaky) unit test and a found data race. 26 # Although Go 1.5 says 'exit status 66' in case of a race, it exits with 1. 27 # Therefore, we manually check the output of 'go test' for data races and 28 # exit with an error if one was found. 29 # TODO(mberlin): Test all packages (go/... instead of go/vt/...) once 30 # go/cgzip is moved into a separate repository. We currently 31 # skip the cgzip package because -race takes >30 sec for it. 32 33 # All endtoend Go packages with test files. 34 # Output per line: <full Go package name> <all _test.go files in the package>* 35 packages_with_tests=$(go list -f '{{if len .TestGoFiles}}{{.ImportPath}} {{join .TestGoFiles " "}}{{end}}{{if len .XTestGoFiles}}{{.ImportPath}} {{join .XTestGoFiles " "}}{{end}}' ./go/.../endtoend/... | sort) 36 packages_with_tests=$(echo "$packages_with_tests" | grep -vE "go/test/endtoend" | cut -d" " -f1) 37 38 # endtoend tests should be in a directory called endtoend 39 all_e2e_tests=$(echo "$packages_with_tests" | cut -d" " -f1) 40 41 # Run all endtoend tests. 42 echo "$all_e2e_tests" | xargs go test $VT_GO_PARALLEL -race 2>&1 | tee $temp_log_file 43 if [ ${PIPESTATUS[0]} -ne 0 ]; then 44 if grep "WARNING: DATA RACE" -q $temp_log_file; then 45 echo 46 echo "ERROR: go test -race found a data race. See log above." 47 exit 2 48 fi 49 50 echo "ERROR: go test -race found NO data race, but failed. See log above." 51 exit 1 52 fi 53 54 echo 55 echo "SUCCESS: No data race was found."