@@ -4,23 +4,64 @@ rerun_failed=false
44specific_test=" "
55specific_package=" "
66cleanup_id=" "
7+ slow_mode=false
78
8- while getopts " :r:t :p:c:" opt; do
9+ while getopts " :rst :p:c:" opt; do
910 case $opt in
1011 r) rerun_failed=true ;;
1112 t) specific_test=" $OPTARG " ;;
1213 p) specific_package=" $OPTARG " ;;
1314 c) cleanup_id=" $OPTARG " ;;
15+ s) slow_mode=true ;;
1416 \? ) cat << EOT >&2 && exit 1 ;;
1517Invalid option -$OPTARG , valid options are
1618 -r to re-run failed tests
17- -t to specify a specific test (eg. TestBase)
18- -p to specify a specific test package (eg. base)
19+ -s to run tests in slow mode (one at a time to avoid AWS rate limiting)
1920 -c to run clean up only with the given id (eg. abc123)
21+ -t to specify a specific test (eg. TestBase)
22+ -p to specify a specific test package (eg. one)
23+ Only one of -c, -t, or -p can be used at a time.
2024EOT
2125 esac
2226done
2327
28+ if [ $slow_mode == true ]; then
29+ echo " Running in slow mode: tests will be run one at a time to avoid AWS rate limiting."
30+ elif [ $slow_mode == false ]; then
31+ echo " Running in normal mode: tests will be run in parallel."
32+ fi
33+ if [ $rerun_failed == true ]; then
34+ echo " Rerun failed tests is enabled."
35+ elif [ $rerun_failed == false ]; then
36+ echo " Rerun failed tests is disabled."
37+ fi
38+ if [ -n " $specific_test " ]; then
39+ echo " Specific test to run: $specific_test "
40+ else
41+ echo " No specific test to run."
42+ fi
43+ if [ -n " $specific_package " ]; then
44+ echo " Specific package to run: $specific_package "
45+ else
46+ echo " No specific package to run."
47+ fi
48+ if [ -n " $cleanup_id " ]; then
49+ echo " Cleanup only mode enabled with id: $cleanup_id "
50+ fi
51+ if [ -n " $cleanup_id " ] && { [ -n " $specific_test " ] || [ -n " $specific_package " ]; }; then
52+ echo " Error: Only one of -c, -t, or -p can be used at a time." >&2
53+ exit 1
54+ fi
55+ if [ -n " $specific_test " ] && { [ -n " $specific_package " ] || [ -n " $cleanup_id " ]; }; then
56+ echo " Error: Only one of -c, -t, or -p can be used at a time." >&2
57+ exit 1
58+ fi
59+ if [ -n " $specific_package " ] && { [ -n " $specific_test " ] || [ -n " $cleanup_id " ]; }; then
60+ echo " Error: Only one of -c, -t, or -p can be used at a time." >&2
61+ exit 1
62+ fi
63+
64+
2465# shellcheck disable=SC2143
2566if [ -n " $cleanup_id " ]; then
2667 export IDENTIFIER=" $cleanup_id "
@@ -30,6 +71,7 @@ REPO_ROOT="$(git rev-parse --show-toplevel)"
3071
3172run_tests () {
3273 local rerun=$1
74+ local slow_mode=$2
3375 REPO_ROOT=" $( git rev-parse --show-toplevel) "
3476 cd " $REPO_ROOT " || exit 1
3577
85127 else
86128 package_pattern=" ..."
87129 fi
88- # We need both -p and -parallel, as -p sets the number of packages to test in parallel, and -parallel sets the number of tests to run in parallel.
89- # By setting both to 1, we ensure that tests are run sequentially, which can help avoid AWS rate limiting issues. I does increase the runtime significantly though.
130+
131+ # We need both -p and -parallel, as -p sets the number of packages to test in parallel,
132+ # and -parallel sets the number of tests to run in parallel.
133+ # By setting both to 1, we ensure that tests are run sequentially, which can help avoid AWS rate limiting issues.
134+ # It does increase the runtime significantly though.
135+ local parallel_packages=" "
136+ local parallel_tests=" "
137+ if [ " $slow_mode " = true ]; then
138+ echo " Running in slow mode..."
139+ parallel_packages=" -p=1"
140+ parallel_tests=" -parallel=1"
141+ fi
142+
143+ CMD=$( cat << EOT
144+ gotestsum \
145+ --format=standard-verbose \
146+ --jsonfile "/tmp/${IDENTIFIER} _test.log" \
147+ --post-run-command "sh /tmp/${IDENTIFIER} _test-processor" \
148+ --packages "$REPO_ROOT /$TEST_DIR /$package_pattern " \
149+ -- \
150+ -count=1 \
151+ -timeout=300m \
152+ -failfast \
153+ $parallel_packages \
154+ $parallel_tests \
155+ $rerun_flag \
156+ $specific_test_flag
157+ EOT
158+ )
159+ echo " Running command: $CMD "
160+
90161 # shellcheck disable=SC2086
91162 gotestsum \
92163 --format=standard-verbose \
95166 --packages " $REPO_ROOT /$TEST_DIR /$package_pattern " \
96167 -- \
97168 -count=1 \
98- -p=1 \
99- -parallel=1 \
100169 -timeout=300m \
101170 -failfast \
171+ $parallel_packages \
172+ $parallel_tests \
102173 $rerun_flag \
103174 $specific_test_flag
104175
@@ -136,13 +207,13 @@ if [ -z "$cleanup_id" ]; then
136207 echo " terraform configs valid..."
137208
138209 # Run tests initially
139- run_tests false
210+ run_tests false " $slow_mode "
140211 sleep 60
141212
142213 # Check if we need to rerun failed tests
143214 if [ " $rerun_failed " = true ] && [ -f " /tmp/${IDENTIFIER} _failed_tests.txt" ]; then
144215 echo " Rerunning failed tests..."
145- run_tests true
216+ run_tests true " $slow_mode "
146217 sleep 60
147218 fi
148219fi
0 commit comments