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: https://github.com/nodejs/node/pull/32623
Refs: https://github.com/nodejs/node/pull/32531
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit is contained in:
Anna Henningsen 2020-04-02 23:43:20 +02:00
parent f621536d81
commit e629366fc6
No known key found for this signature in database
GPG Key ID: A94130F0BFC8EBE9
2 changed files with 17 additions and 0 deletions

View File

@ -1014,6 +1014,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);

View File

@ -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()));