diff --git a/test/parallel/test-worker-cleanup-handles.js b/test/parallel/test-worker-cleanup-handles.js new file mode 100644 index 0000000000..6d3b257bb0 --- /dev/null +++ b/test/parallel/test-worker-cleanup-handles.js @@ -0,0 +1,24 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { Worker } = require('worker'); +const { Server } = require('net'); +const fs = require('fs'); + +if (process.isMainThread) { + const w = new Worker(__filename); + let fd = null; + w.on('message', common.mustCall((fd_) => { + assert.strictEqual(typeof fd_, 'number'); + fd = fd_; + })); + w.on('exit', common.mustCall((code) => { + assert.throws(() => fs.fstatSync(fd), + common.expectsError({ code: 'EBADF' })); + })); +} else { + const server = new Server(); + server.listen(0); + process.postMessage(server._handle.fd); + server.unref(); +} diff --git a/test/parallel/test-worker-uncaught-exception-async.js b/test/parallel/test-worker-uncaught-exception-async.js new file mode 100644 index 0000000000..6a7bed062e --- /dev/null +++ b/test/parallel/test-worker-uncaught-exception-async.js @@ -0,0 +1,17 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { Worker } = require('worker'); + +if (process.isMainThread) { + const w = new Worker(__filename); + w.on('message', common.mustNotCall()); + w.on('error', common.mustCall((err) => { + // TODO(addaleax): be more specific here + assert(/foo/.test(err)); + })); +} else { + setImmediate(() => { + throw new Error('foo'); + }); +} diff --git a/test/parallel/test-worker-uncaught-exception.js b/test/parallel/test-worker-uncaught-exception.js new file mode 100644 index 0000000000..f34e5b4647 --- /dev/null +++ b/test/parallel/test-worker-uncaught-exception.js @@ -0,0 +1,15 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { Worker } = require('worker'); + +if (process.isMainThread) { + const w = new Worker(__filename); + w.on('message', common.mustNotCall()); + w.on('error', common.mustCall((err) => { + // TODO(addaleax): be more specific here + assert(/foo/.test(err)); + })); +} else { + throw new Error('foo'); +} diff --git a/test/parallel/test-worker.js b/test/parallel/test-worker.js new file mode 100644 index 0000000000..78d1c38739 --- /dev/null +++ b/test/parallel/test-worker.js @@ -0,0 +1,17 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { Worker } = require('worker'); + +if (process.isMainThread) { + const w = new Worker(__filename); + w.on('message', common.mustCall((message) => { + assert.strictEqual(message, 'Hello, world!'); + })); +} else { + setImmediate(() => { + process.nextTick(() => { + process.postMessage('Hello, world!'); + }); + }); +}