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 <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent a47ee80 commit 1827256

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

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+
constcommon=require('../common');
9+
common.skipIfWorker();
10+
11+
constassert=require('assert');
12+
13+
const{ Worker, isMainThread }=require('worker_threads');
14+
if(isMainThread){
15+
constworker=newWorker(__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+
constmessagePort=getEnvMessagePort();
24+
messagePort.postMessage({type: messageTypes.COULD_NOT_SERIALIZE_ERROR});
25+
}

0 commit comments

Comments
 (0)