Skip to content

Commit 1827256

Browse files
Trotttargos
authored andcommitted
test: add coverage for unserializable worker thread error
Check that the main thread handles unserializable errors in a worker thread as expected. PR-URL: #27995 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent a47ee80 commit 1827256

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
// Flags: --expose-internals
4+
5+
// Check that main thread handles unserializable errors in a worker thread as
6+
// expected.
7+
8+
const common = require('../common');
9+
common.skipIfWorker();
10+
11+
const assert = require('assert');
12+
13+
const { Worker, isMainThread } = require('worker_threads');
14+
if (isMainThread) {
15+
const worker = new Worker(__filename);
16+
worker.on('error', common.mustCall((e) => {
17+
assert.strictEqual(e.code, 'ERR_WORKER_UNSERIALIZABLE_ERROR');
18+
}));
19+
} else {
20+
const { internalBinding } = require('internal/test/binding');
21+
const { getEnvMessagePort } = internalBinding('worker');
22+
const { messageTypes } = require('internal/worker/io');
23+
const messagePort = getEnvMessagePort();
24+
messagePort.postMessage({ type: messageTypes.COULD_NOT_SERIALIZE_ERROR });
25+
}

0 commit comments

Comments
 (0)