Skip to content

Commit 4dca3ab

Browse files
gireeshpunathiladdaleax
authored andcommitted
test: exit sequence sanity tests
Execute JS code in worker through same vm context 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: #25085 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent b06f2fa commit 4dca3ab

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
const common = 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 running a lot of
7+
// JS code in a tight loop, the expectation
8+
// is that those will be at various control flow points
9+
// preferrably in the JS land.
10+
11+
const { Worker } = require('worker_threads');
12+
const code = 'setInterval(() => {' +
13+
"require('v8').deserialize(require('v8').serialize({ foo: 'bar' }));" +
14+
"require('vm').runInThisContext('x = \"foo\";');" +
15+
"eval('const y = \"vm\";');}, 10);";
16+
for (let i = 0; i < 9; i++) {
17+
new Worker(code, { eval: true });
18+
}
19+
new Worker(code, { eval: true }).on('online', common.mustCall((msg) => {
20+
process.exit(0);
21+
}));

0 commit comments

Comments
 (0)