Skip to content

Commit 72f52a3

Browse files
addaleaxtargos
authored andcommitted
test: add Worker + uncaughtException + process.exit() test
PR-URL: #28259 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 5b92eb4 commit 72f52a3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { Worker } = require('worker_threads');
5+
6+
// Check that `process.exit()` can be called inside a Worker from an uncaught
7+
// exception handler.
8+
9+
// Do not use isMainThread so that this test itself can be run inside a Worker.
10+
if (!process.env.HAS_STARTED_WORKER) {
11+
process.env.HAS_STARTED_WORKER = 1;
12+
const w = new Worker(__filename);
13+
w.on('exit', common.mustCall((code) => {
14+
assert.strictEqual(code, 42);
15+
}));
16+
return;
17+
}
18+
19+
process.on('uncaughtException', () => {
20+
process.exit(42);
21+
});
22+
23+
throw new Error();

0 commit comments

Comments
 (0)