-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(workers): Test that closing a worker closes any child workers (#…
…12215) Before #12156, closing a worker which had children would cause a panic (#11342 (comment)). After that PR, closing a worker will also close any child workers.
- Loading branch information
Andreu Botella
authored
Sep 25, 2021
1 parent
4e2b59f
commit 1a6249c
Showing
5 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Starting the main thread | ||
Starting the parent worker | ||
Starting the child worker | ||
About to close | ||
Closing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); |