summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/worker_tests.rs5
-rw-r--r--cli/tests/testdata/workers/terminate_tla_crash.js21
-rw-r--r--cli/tests/testdata/workers/terminate_tla_crash.js.out0
3 files changed, 26 insertions, 0 deletions
diff --git a/cli/tests/integration/worker_tests.rs b/cli/tests/integration/worker_tests.rs
index c17b63af9..8bb051ff3 100644
--- a/cli/tests/integration/worker_tests.rs
+++ b/cli/tests/integration/worker_tests.rs
@@ -99,3 +99,8 @@ itest!(worker_permissions_blob_local {
http_server: true,
exit_code: 1,
});
+
+itest!(worker_terminate_tla_crash {
+ args: "run --quiet --reload workers/terminate_tla_crash.js",
+ output: "workers/terminate_tla_crash.js.out",
+});
diff --git a/cli/tests/testdata/workers/terminate_tla_crash.js b/cli/tests/testdata/workers/terminate_tla_crash.js
new file mode 100644
index 000000000..f793b8c8e
--- /dev/null
+++ b/cli/tests/testdata/workers/terminate_tla_crash.js
@@ -0,0 +1,21 @@
+// Test for https://github.com/denoland/deno/issues/12658
+//
+// If a worker is terminated immediately after construction, and the worker's
+// main module uses top-level await, V8 has a chance to crash.
+//
+// These crashes are so rare in debug mode that I've only seen them once. They
+// happen a lot more often in release mode.
+
+const workerModule = `
+ await new Promise(resolve => setTimeout(resolve, 1000));
+`;
+
+// Iterating 10 times to increase the likelihood of triggering the crash, at
+// least in release mode.
+for (let i = 0; i < 10; i++) {
+ const worker = new Worker(
+ `data:application/javascript;base64,${btoa(workerModule)}`,
+ { type: "module" },
+ );
+ worker.terminate();
+}
diff --git a/cli/tests/testdata/workers/terminate_tla_crash.js.out b/cli/tests/testdata/workers/terminate_tla_crash.js.out
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/cli/tests/testdata/workers/terminate_tla_crash.js.out