Skip to content

Commit ae19f94

Browse files
gireeshpunathiltargos
authored andcommitted
test: exit sequence sanity tests
Execute many module loads in worker in a loop while exiting from the main thread at arbitrary execution points, and make sure that the workers quiesce without crashing. `worker_threads` are not necessarily the subject of testing, those are used for easy simulation of multi-thread scenarios. Refs: #25007 PR-URL: #25083 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c56ddc7 commit ae19f94

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
require('../common');
3+
4+
// Harden the thread interactions on the exit path.
5+
// Ensure workers are able to bail out safe at
6+
// arbitrary execution points. By using a number of
7+
// internal modules as load candidates, the expectation
8+
// is that those will be at various control flow points
9+
// preferrably in the C++ land.
10+
11+
const { Worker } = require('worker_threads');
12+
for (let i = 0; i < 10; i++) {
13+
new Worker("const modules = ['fs', 'assert', 'async_hooks'," +
14+
"'buffer', 'child_process', 'net', 'http', 'https', 'os'," +
15+
"'path', 'v8', 'vm'];" +
16+
'modules.forEach((module) => {' +
17+
'const m = require(module);' +
18+
'});', { eval: true });
19+
}
20+
21+
// Allow workers to go live.
22+
setTimeout(() => {
23+
process.exit(0);
24+
}, 200);

0 commit comments

Comments
 (0)