Skip to content

Commit f17a4da

Browse files
authored
fix: create a slow mode for testing (#131)
Signed-off-by: matttrach <[email protected]>
1 parent 59a71fc commit f17a4da

File tree

5 files changed

+95
-64
lines changed

5 files changed

+95
-64
lines changed

.github/workflows/manual.yaml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ jobs:
7373
repo: "${{ github.event.repository.name }}",
7474
body: "Please make sure e2e tests pass before merging this PR! \n ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
7575
})
76+
77+
test:
78+
needs:
79+
- release
80+
if: needs.release.outputs.release_pr
81+
runs-on: ubuntu-latest
82+
steps:
7683
- uses: actions/checkout@v5
7784
with:
7885
token: ${{secrets.GITHUB_TOKEN}}
@@ -83,7 +90,7 @@ jobs:
8390
role-to-assume: ${{env.AWS_ROLE}}
8491
role-session-name: ${{github.run_id}}
8592
aws-region: ${{env.AWS_REGION}}
86-
role-duration-seconds: 14400 # 4 hours
93+
role-duration-seconds: 28800 # 8 hours
8794
output-credentials: true
8895
- name: install-nix
8996
run: |
@@ -106,12 +113,12 @@ jobs:
106113
ACME_SERVER_URL: https://acme-v02.api.letsencrypt.org/directory
107114
RANCHER_INSECURE: false
108115
run: |
109-
# should take around 4 hours
110-
./run_tests.sh
116+
./run_tests.sh -s
111117
112118
cleanup:
113119
needs:
114120
- release
121+
- test
115122
if: always() && needs.release.outputs.release_pr
116123
runs-on: ubuntu-latest
117124
steps:
@@ -147,6 +154,7 @@ jobs:
147154
report:
148155
needs:
149156
- release
157+
- test
150158
- cleanup
151159
if: success() && needs.release.outputs.release_pr #Ensure the test jobs succeeded, and that a release PR was created.
152160
runs-on: ubuntu-latest

modules/deploy/create.sh.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ E1=0
1818
while [ $EXITCODE -gt 0 ] && [ $ATTEMPTS -lt $MAX ]; do
1919
A=0
2020
while [ $E -gt 0 ] && [ $A -lt $MAX ]; do
21-
timeout -k 1m ${timeout} terraform apply -var-file="${deploy_path}/inputs.tfvars" -auto-approve -state="${deploy_path}/tfstate"
21+
timeout -k 1m ${timeout} terraform apply -var-file="${deploy_path}/inputs.tfvars" -no-color -auto-approve -state="${deploy_path}/tfstate"
2222
E=$?
2323
if [ $E -eq 124 ]; then echo "Apply timed out after ${timeout}"; fi
2424
A=$((A+1))
@@ -27,7 +27,7 @@ while [ $EXITCODE -gt 0 ] && [ $ATTEMPTS -lt $MAX ]; do
2727
if [ $E -gt 0 ] && [ $ATTEMPTS != $((MAX-1)) ]; then
2828
A1=0
2929
while [ $E1 -gt 0 ] && [ $A1 -lt $MAX ]; do
30-
timeout -k 1m ${timeout} terraform destroy -var-file="${deploy_path}/inputs.tfvars" -auto-approve -state="${deploy_path}/tfstate"
30+
timeout -k 1m ${timeout} terraform destroy -var-file="${deploy_path}/inputs.tfvars" -no-color -auto-approve -state="${deploy_path}/tfstate"
3131
E1=$?
3232
if [ $E1 -eq 124 ]; then echo "Apply timed out after ${timeout}"; fi
3333
A1=$((A1+1))

modules/deploy/destroy.sh.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ whoami
88
TF_CLI_ARGS_init=""
99
TF_CLI_ARGS_apply=""
1010
if [ -z "${skip_destroy}" ]; then
11-
timeout -k 1m ${timeout} terraform init -upgrade -reconfigure
12-
timeout -k 1m ${timeout} terraform destroy -var-file="${deploy_path}/inputs.tfvars" -auto-approve -state="${deploy_path}/tfstate" || true
11+
timeout -k 1m ${timeout} terraform init -upgrade -reconfigure -no-color
12+
timeout -k 1m ${timeout} terraform destroy -var-file="${deploy_path}/inputs.tfvars" -no-color -auto-approve -state="${deploy_path}/tfstate" || true
1313
else
1414
echo "Not destroying deployed module, it will no longer be managed here."
1515
fi

run_tests.sh

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,64 @@ rerun_failed=false
44
specific_test=""
55
specific_package=""
66
cleanup_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 ;;
1517
Invalid 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.
2024
EOT
2125
esac
2226
done
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
2566
if [ -n "$cleanup_id" ]; then
2667
export IDENTIFIER="$cleanup_id"
@@ -30,6 +71,7 @@ REPO_ROOT="$(git rev-parse --show-toplevel)"
3071

3172
run_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

@@ -85,8 +127,37 @@ EOF
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 \
@@ -95,10 +166,10 @@ EOF
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
148219
fi

0 commit comments

Comments
 (0)