summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-03-15 20:38:16 +0000
committerGitHub <noreply@github.com>2024-03-15 21:38:16 +0100
commitc342cd36ba1af12d005167369d3a2f508496ef5d (patch)
treef875512a283166eae46dfddf5ca26f29c482499e /tests
parente40f9a5c14c51b6d05812e48fa072148fe79c74d (diff)
fix(ext/node): worker_threads doesn't exit if there are message listeners (#22944)
Closes https://github.com/denoland/deno/issues/22934
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/worker_tests.rs1
-rw-r--r--tests/testdata/workers/node_worker_auto_exits.mjs12
-rw-r--r--tests/testdata/workers/node_worker_auto_exits.mjs.out1
3 files changed, 13 insertions, 1 deletions
diff --git a/tests/integration/worker_tests.rs b/tests/integration/worker_tests.rs
index 8fdef8b2b..dd0c2d409 100644
--- a/tests/integration/worker_tests.rs
+++ b/tests/integration/worker_tests.rs
@@ -119,6 +119,7 @@ itest!(worker_ids_are_sequential {
});
// Test for https://github.com/denoland/deno/issues/22629
+// Test for https://github.com/denoland/deno/issues/22934
itest!(node_worker_auto_exits {
args: "run --quiet --allow-read workers/node_worker_auto_exits.mjs",
output: "workers/node_worker_auto_exits.mjs.out",
diff --git a/tests/testdata/workers/node_worker_auto_exits.mjs b/tests/testdata/workers/node_worker_auto_exits.mjs
index abfb084c3..e434f59f7 100644
--- a/tests/testdata/workers/node_worker_auto_exits.mjs
+++ b/tests/testdata/workers/node_worker_auto_exits.mjs
@@ -1,9 +1,19 @@
-import { isMainThread, Worker } from "node:worker_threads";
+import { isMainThread, parentPort, Worker } from "node:worker_threads";
+
+function onMessageOneshot() {
+ console.log("Got message from main thread!");
+ parentPort.off("message", onMessageOneshot);
+}
if (isMainThread) {
// This re-loads the current file inside a Worker instance.
const w = new Worker(import.meta.filename);
+
+ setTimeout(() => {
+ w.postMessage("Hello! I am from the main thread.");
+ }, 500);
} else {
console.log("Inside Worker!");
console.log(isMainThread); // Prints 'false'.
+ parentPort.on("message", onMessageOneshot);
}
diff --git a/tests/testdata/workers/node_worker_auto_exits.mjs.out b/tests/testdata/workers/node_worker_auto_exits.mjs.out
index 18934d3ed..a160931db 100644
--- a/tests/testdata/workers/node_worker_auto_exits.mjs.out
+++ b/tests/testdata/workers/node_worker_auto_exits.mjs.out
@@ -1,2 +1,3 @@
Inside Worker!
false
+Got message from main thread!