File
Blob: src/workerd/api/tests/abortIsolate.sh
| 1 | #!/bin/bash |
| 2 | # Call abortIsolate() and check for: |
| 3 | # * exit code nonzero |
| 4 | # * fatal uncaught exception message present with the abort reason. |
| 5 | |
| 6 | WORKERD=$1 |
| 7 | CONFIG=$2 |
| 8 | JSFILE=$3 |
| 9 | TEST_TMPDIR="${TEST_TMPDIR:-/tmp}" |
| 10 | |
| 11 | cp "$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. |
| 15 | run_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. |
| 32 | expect_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 | |
| 40 | failed=0 |
| 41 | |
| 42 | echo "Test 1: topLevelAbort = false" |
| 43 | run_test false |
| 44 | |
| 45 | if [ "$exit_code" -eq 0 ]; then |
| 46 | echo "FAIL: expected nonzero exit code" >&2 |
| 47 | exit 1 |
| 48 | fi |
| 49 | |
| 50 | expect_in_output "*** Fatal uncaught kj::Exception:" |
| 51 | expect_in_output "abortIsolate() called, terminating process; reason = test reason" |
| 52 | |
| 53 | echo "Test 2: topLevelAbort = true" |
| 54 | run_test true |
| 55 | |
| 56 | if [ "$exit_code" -eq 0 ]; then |
| 57 | echo "FAIL: expected nonzero exit code" >&2 |
| 58 | exit 1 |
| 59 | fi |
| 60 | |
| 61 | if [ "$failed" -ne 0 ]; then |
| 62 | exit 1 |
| 63 | fi |
| 64 | |
| 65 | echo "Success" |
| 66 | exit 0 |