Skip to content

Commit

Permalink
test: add coverage for unserializable worker thread error
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Trott authored and targos committed Jun 3, 2019
1 parent a47ee80 commit 1827256
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/parallel/test-worker-message-not-serializable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

// Flags: --expose-internals

// Check that main thread handles unserializable errors in a worker thread as
// expected.

const common = require('../common');
common.skipIfWorker();

const assert = require('assert');

const { Worker, isMainThread } = require('worker_threads');
if (isMainThread) {
const worker = new Worker(__filename);
worker.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, 'ERR_WORKER_UNSERIALIZABLE_ERROR');
}));
} else {
const { internalBinding } = require('internal/test/binding');
const { getEnvMessagePort } = internalBinding('worker');
const { messageTypes } = require('internal/worker/io');
const messagePort = getEnvMessagePort();
messagePort.postMessage({ type: messageTypes.COULD_NOT_SERIALIZE_ERROR });
}

0 comments on commit 1827256

Please sign in to comment.