55set -e
66
77function usage() {
8- echo " Usage: $0 [--tags tag1,tag2,...] [package_path] TestName [stress options...]"
8+ echo " Usage: $0 [--tags tag1,tag2,...] [--race] [ package_path] TestName [stress options...]"
99 echo " "
1010 echo " --tags: Optional comma-separated list of build tags"
11+ echo " --race: Enable race detection"
1112 echo " package_path: Path to the Go package containing the tests."
1213 echo " TestName: Regular expression to match the test to run, equivalent to -test.run."
1314 echo " [stress options]: Options to pass to the stress command."
1415 echo " "
1516 echo " Examples:"
1617 echo " $0 ./libbeat/common/backoff ^TestBackoff$ -p 32"
17- echo " $0 --tags integration ./libbeat/common/backoff ^TestBackoff$ -p 32"
18+ echo " $0 --tags integration --race ./libbeat/common/backoff ^TestBackoff$ -p 32"
1819}
1920
2021if [[ " $1 " == " --help" || " $1 " == " -h" ]]; then
@@ -34,6 +35,13 @@ if [[ "$1" == "--tags" ]]; then
3435 shift 2
3536fi
3637
38+ # Parse optional --race parameter
39+ race_flag=" "
40+ if [[ " $1 " == " --race" ]]; then
41+ race_flag=" -race"
42+ shift 1
43+ fi
44+
3745if [[ $# -lt 2 ]]; then
3846 echo " Error: Missing arguments."
3947 usage
@@ -54,9 +62,9 @@ stress_options=("${@:3}")
5462cd " $test_package_path "
5563rm " $test_exec_file " 2> /dev/null || true
5664if [[ -n " $build_tags " ]]; then
57- go test -tags " $build_tags " -c -o " ./$test_exec_file "
65+ go test -tags " $build_tags " $race_flag -c -o " ./$test_exec_file "
5866else
59- go test -c -o " ./$test_exec_file "
67+ go test $race_flag -c -o " ./$test_exec_file "
6068fi
6169trap ' rm "./$test_exec_file" 2>/dev/null || true' EXIT INT TERM
6270go run golang.org/x/tools/cmd/stress@latest " ${stress_options[@]} " " ./$test_exec_file " -test.run " $test_regex " -test.v
0 commit comments