0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-worker-message-not-serializable.js
Rich Trott e8f3119190 test: handle unknown message type in worker threads
Check that main thread handles an unknown message type from a worker
thread as expected.

PR-URL: https://github.com/nodejs/node/pull/27995
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-06-02 17:50:54 +02:00

25 lines
721 B
JavaScript

'use strict';
// Flags: --expose-internals
// Check that main thread handles unserializable errors in a worker thread as
// expected.
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');
const worker = new Worker(`
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 });
`, { eval: true });
worker.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, 'ERR_WORKER_UNSERIALIZABLE_ERROR');
}));