Skip to content

Commit 6cef0e3

Browse files
addaleaxrichardlau
authored andcommitted
src,test: add regression test for nested Worker termination
This adds a regression test for terminating a Worker inside which another Worker is running. PR-URL: #32623 Refs: #32531 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 0a35d49 commit 6cef0e3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

‎src/env.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,8 @@ void Environment::Exit(int exit_code){
10381038
}
10391039

10401040
voidEnvironment::stop_sub_worker_contexts(){
1041+
DCHECK_EQ(Isolate::GetCurrent(), isolate());
1042+
10411043
while (!sub_worker_contexts_.empty()){
10421044
Worker* w = *sub_worker_contexts_.begin();
10431045
remove_sub_worker_context(w);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
const{ Worker }=require('worker_threads');
4+
5+
// Check that a Worker that's running another Worker can be terminated.
6+
7+
constworker=newWorker(`
8+
const{Worker, parentPort } = require('worker_threads');
9+
const worker = new Worker('setInterval(() =>{}, 10);',{eval: true });
10+
worker.on('online', () =>{
11+
parentPort.postMessage({});
12+
});
13+
`,{eval: true});
14+
15+
worker.on('message',common.mustCall(()=>worker.terminate()));

0 commit comments

Comments
(0)