Skip to content

Commit 339f6ed

Browse files
authored
Use trap to always run sls remove when exiting integration tests (#129)
1 parent d289ce5 commit 339f6ed

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

scripts/run_integration_tests.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ input_event_files=($(for file_name in ${input_event_files[@]}; do echo $file_nam
5555
# Generate a random 8-character ID to avoid collisions with other runs
5656
run_id=$(xxd -l 4 -c 4 -p < /dev/random)
5757

58+
# Always remove the stack before exiting, no matter what
59+
function remove_stack() {
60+
echo "Removing functions"
61+
serverless remove --stage $run_id
62+
}
63+
trap remove_stack EXIT
64+
5865
echo "Deploying functions"
5966
serverless deploy --stage $run_id
6067

@@ -125,9 +132,6 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
125132
echo "Error from final attempt to retrieve logs:"
126133
echo $raw_logs
127134

128-
echo "Removing functions"
129-
serverless remove --stage $run_id
130-
131135
exit 1
132136
fi
133137

@@ -191,9 +195,6 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
191195
done
192196
set -e
193197

194-
echo "Removing functions"
195-
serverless remove --stage $run_id
196-
197198
if [ "$mismatch_found" = true ]; then
198199
echo "FAILURE: A mismatch between new data and a snapshot was found and printed above."
199200
echo "If the change is expected, generate new snapshots by running 'UPDATE_SNAPSHOTS=true DD_API_KEY=XXXX ./scripts/run_integration_tests.sh'"

0 commit comments

Comments
 (0)