Skip to content
File

Blob: src/workerd/api/tests/abortIsolate.sh

bash67 lines
1#!/bin/bash
2# Call abortIsolate() and check for:
3# * exit code nonzero
4# * fatal uncaught exception message present with the abort reason.
5 
6WORKERD=$1
7CONFIG=$2
8JSFILE=$3
9TEST_TMPDIR="${TEST_TMPDIR:-/tmp}"
10 
11cp "$JSFILE" "$TEST_TMPDIR"
12 
13# Prepare the config with a given topLevelAbort value and run workerd.
14# Sets the global `output` and `exit_code` variables.
15run_test() {
16 local top_level_abort=$1
17 cp "$CONFIG" "$TEST_TMPDIR"
18 sed "s/%topLevelAbort/$top_level_abort/" "$TEST_TMPDIR/abortIsolate.wd-test" \
19 > "$TEST_TMPDIR/abortIsolate.wd-test.tmp" \
20 && mv "$TEST_TMPDIR/abortIsolate.wd-test.tmp" "$TEST_TMPDIR/abortIsolate.wd-test"
21 
22 output=$("$WORKERD" test "$TEST_TMPDIR/abortIsolate.wd-test" --experimental --compat-date=2000-01-01 -dTEST_TMPDIR="$TEST_TMPDIR" 2>&1)
23 exit_code=$?
24 
25 echo "--- captured output ---" >&2
26 echo "$output" >&2
27 echo "--- end captured output ---" >&2
28 echo "" >&2
29}
30 
31# Assert that $output contains the given string; set failed=1 on mismatch.
32expect_in_output() {
33 local msg=$1
34 if ! echo "$output" | grep -qF "$msg"; then
35 echo "FAIL: expected log line not found: $msg" >&2
36 failed=1
37 fi
38}
39 
40failed=0
41 
42echo "Test 1: topLevelAbort = false"
43run_test false
44 
45if [ "$exit_code" -eq 0 ]; then
46 echo "FAIL: expected nonzero exit code" >&2
47 exit 1
48fi
49 
50expect_in_output "*** Fatal uncaught kj::Exception:"
51expect_in_output "abortIsolate() called, terminating process; reason = test reason"
52 
53echo "Test 2: topLevelAbort = true"
54run_test true
55 
56if [ "$exit_code" -eq 0 ]; then
57 echo "FAIL: expected nonzero exit code" >&2
58 exit 1
59fi
60 
61if [ "$failed" -ne 0 ]; then
62 exit 1
63fi
64 
65echo "Success"
66exit 0