Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the unit race test raise errors #5499

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions tools/unit_test_race.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.

temp_log_file="$(mktemp --suffix .unit_test_race.log)"
trap '[ -f "$temp_log_file" ] && rm $temp_log_file' EXIT

# Wrapper around go test -race.

# This script exists because the -race test doesn't allow to distinguish
# between a failed (e.g. flaky) unit test and a found data race.
# Although Go 1.5 says 'exit status 66' in case of a race, it exits with 1.
# Therefore, we manually check the output of 'go test' for data races and
# exit with an error if one was found.
# TODO(mberlin): Test all packages (go/... instead of go/vt/...) once
# go/cgzip is moved into a separate repository. We currently
# skip the cgzip package because -race takes >30 sec for it.
if [[ -z $VT_GO_PARALLEL && -n $VT_GO_PARALLEL_VALUE ]]; then
VT_GO_PARALLEL="-p $VT_GO_PARALLEL_VALUE"
fi

# All Go packages with test files.
# Output per line: <full Go package name> <all _test.go files in the package>*
# TODO: This tests ./go/vt/... instead of ./go/... due to a historical reason.
# When https://github.com/vitessio/vitess/issues/5493 is closed, we should change it.

packages_with_tests=$(go list -f '{{if len .TestGoFiles}}{{.ImportPath}} {{join .TestGoFiles " "}}{{end}}' ./go/vt/... | sort)

# endtoend tests should be in a directory called endtoend
all_except_e2e_tests=$(echo "$packages_with_tests" | cut -d" " -f1 | grep -v "endtoend")

# Run non endtoend tests.
echo "$all_except_e2e_tests" | xargs go test $VT_GO_PARALLEL -race 2>&1 | tee $temp_log_file
if [ ${PIPESTATUS[0]} -ne 0 ]; then
if grep "WARNING: DATA RACE" -q $temp_log_file; then
echo
echo "ERROR: go test -race found a data race. See log above."
exit 2
fi
echo "$all_except_e2e_tests" | xargs go test $VT_GO_PARALLEL -race

echo "ERROR: go test -race found NO data race, but failed. See log above."
if [ $? -ne 0 ]; then
echo "WARNING: POSSIBLE DATA RACE"
echo
echo "ERROR: go test -race failed. See log above."
exit 1
fi

echo
echo "SUCCESS: No data race was found."