Skip to content

Commit 35d827f

Browse files
feat(script): add race support for stresstest (#47174) (#47187)
(cherry picked from commit 9e60856) Co-authored-by: Mauri de Souza Meneguzzo <[email protected]>
1 parent 54e1de5 commit 35d827f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

script/stresstest.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
set -e
66

77
function 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

2021
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
@@ -34,6 +35,13 @@ if [[ "$1" == "--tags" ]]; then
3435
shift 2
3536
fi
3637

38+
# Parse optional --race parameter
39+
race_flag=""
40+
if [[ "$1" == "--race" ]]; then
41+
race_flag="-race"
42+
shift 1
43+
fi
44+
3745
if [[ $# -lt 2 ]]; then
3846
echo "Error: Missing arguments."
3947
usage
@@ -54,9 +62,9 @@ stress_options=("${@:3}")
5462
cd "$test_package_path"
5563
rm "$test_exec_file" 2>/dev/null || true
5664
if [[ -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"
5866
else
59-
go test -c -o "./$test_exec_file"
67+
go test $race_flag -c -o "./$test_exec_file"
6068
fi
6169
trap 'rm "./$test_exec_file" 2>/dev/null || true' EXIT INT TERM
6270
go run golang.org/x/tools/cmd/stress@latest "${stress_options[@]}" "./$test_exec_file" -test.run "$test_regex" -test.v

0 commit comments

Comments
 (0)