diff options
Diffstat (limited to 'cli/tests/testdata')
-rw-r--r-- | cli/tests/testdata/worker_close_nested.js | 20 | ||||
-rw-r--r-- | cli/tests/testdata/worker_close_nested.js.out | 5 | ||||
-rw-r--r-- | cli/tests/testdata/workers/close_nested_child.js | 7 | ||||
-rw-r--r-- | cli/tests/testdata/workers/close_nested_parent.js | 13 |
4 files changed, 45 insertions, 0 deletions
diff --git a/cli/tests/testdata/worker_close_nested.js b/cli/tests/testdata/worker_close_nested.js new file mode 100644 index 000000000..fd47a5ae4 --- /dev/null +++ b/cli/tests/testdata/worker_close_nested.js @@ -0,0 +1,20 @@ +// Copyright 2018-2021 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( + new URL("./workers/close_nested_parent.js", import.meta.url), + { 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/cli/tests/testdata/worker_close_nested.js.out b/cli/tests/testdata/worker_close_nested.js.out new file mode 100644 index 000000000..496bc6251 --- /dev/null +++ b/cli/tests/testdata/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 diff --git a/cli/tests/testdata/workers/close_nested_child.js b/cli/tests/testdata/workers/close_nested_child.js new file mode 100644 index 000000000..627a176aa --- /dev/null +++ b/cli/tests/testdata/workers/close_nested_child.js @@ -0,0 +1,7 @@ +// Copyright 2018-2021 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!!!"); +}, 2000); diff --git a/cli/tests/testdata/workers/close_nested_parent.js b/cli/tests/testdata/workers/close_nested_parent.js new file mode 100644 index 000000000..c528632ce --- /dev/null +++ b/cli/tests/testdata/workers/close_nested_parent.js @@ -0,0 +1,13 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +console.log("Starting the parent worker"); + +new Worker( + new URL("./close_nested_child.js", import.meta.url), + { type: "module" }, +); + +self.addEventListener("message", () => { + console.log("Closing"); + self.close(); +}); |