diff options
Diffstat (limited to 'tests/specs/run/worker_close_nested')
5 files changed, 50 insertions, 0 deletions
diff --git a/tests/specs/run/worker_close_nested/__test__.jsonc b/tests/specs/run/worker_close_nested/__test__.jsonc new file mode 100644 index 000000000..5cce107c7 --- /dev/null +++ b/tests/specs/run/worker_close_nested/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run --quiet --reload --allow-read worker_close_nested.js", + "output": "worker_close_nested.js.out" +} diff --git a/tests/specs/run/worker_close_nested/close_nested_child.js b/tests/specs/run/worker_close_nested/close_nested_child.js new file mode 100644 index 000000000..97980c689 --- /dev/null +++ b/tests/specs/run/worker_close_nested/close_nested_child.js @@ -0,0 +1,8 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +console.log("Starting the child worker"); + +setTimeout(() => { + console.log("The child worker survived the death of the parent!!!"); + Deno.exit(1); +}, 2000); diff --git a/tests/specs/run/worker_close_nested/close_nested_parent.js b/tests/specs/run/worker_close_nested/close_nested_parent.js new file mode 100644 index 000000000..d1fe47553 --- /dev/null +++ b/tests/specs/run/worker_close_nested/close_nested_parent.js @@ -0,0 +1,13 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +console.log("Starting the parent worker"); + +new Worker( + import.meta.resolve("./close_nested_child.js"), + { type: "module" }, +); + +self.addEventListener("message", () => { + console.log("Closing"); + self.close(); +}); diff --git a/tests/specs/run/worker_close_nested/worker_close_nested.js b/tests/specs/run/worker_close_nested/worker_close_nested.js new file mode 100644 index 000000000..8d9c88d1c --- /dev/null +++ b/tests/specs/run/worker_close_nested/worker_close_nested.js @@ -0,0 +1,20 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// Test that closing a worker which has living child workers will automatically +// close the children. + +console.log("Starting the main thread"); + +const worker = new Worker( + import.meta.resolve("./close_nested_parent.js"), + { type: "module" }, +); + +setTimeout(() => { + console.log("About to close"); + worker.postMessage({}); + + // Keep the process running for another two seconds, to make sure there's no + // output from the child worker. + setTimeout(() => {}, 2000); +}, 1000); diff --git a/tests/specs/run/worker_close_nested/worker_close_nested.js.out b/tests/specs/run/worker_close_nested/worker_close_nested.js.out new file mode 100644 index 000000000..496bc6251 --- /dev/null +++ b/tests/specs/run/worker_close_nested/worker_close_nested.js.out @@ -0,0 +1,5 @@ +Starting the main thread +Starting the parent worker +Starting the child worker +About to close +Closing |