Skip to content

Commit

Permalink
src,test: add regression test for nested Worker termination
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
addaleax authored and richardlau committed Feb 21, 2021
1 parent c54186d commit 0692611
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,8 @@ void Environment::Exit(int exit_code) {
}

void Environment::stop_sub_worker_contexts() {
DCHECK_EQ(Isolate::GetCurrent(), isolate());

while (!sub_worker_contexts_.empty()) {
Worker* w = *sub_worker_contexts_.begin();
remove_sub_worker_context(w);
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-worker-terminate-nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
const common = require('../common');
const { Worker } = require('worker_threads');

// Check that a Worker that's running another Worker can be terminated.

const worker = new Worker(`
const { Worker, parentPort } = require('worker_threads');
const worker = new Worker('setInterval(() => {}, 10);', { eval: true });
worker.on('online', () => {
parentPort.postMessage({});
});
`, { eval: true });

worker.on('message', common.mustCall(() => worker.terminate()));

0 comments on commit 0692611

Please sign in to comment.