summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-cleanup-handles.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-09-01 17:03:41 +0200
committerAnna Henningsen <anna@addaleax.net>2018-06-06 19:43:52 +0200
commit0df031acadcc6490379d72676203a980c8d60592 (patch)
tree3f49864e72b0193ea9af937874f62c6316877ec4 /test/parallel/test-worker-cleanup-handles.js
parent8939f36630bd718fc0b0b8557cf7f2ed9ecab312 (diff)
downloadandroid-node-v8-0df031acadcc6490379d72676203a980c8d60592.tar.gz
android-node-v8-0df031acadcc6490379d72676203a980c8d60592.tar.bz2
android-node-v8-0df031acadcc6490379d72676203a980c8d60592.zip
worker: initial implementation
Implement multi-threading support for most of the API. Thanks to Stephen Belanger for reviewing this change in its original form, to Olivia Hugger for reviewing the documentation and some of the tests coming along with it, and to Alexey Orlenko and Timothy Gu for reviewing other parts of the tests. Refs: https://github.com/ayojs/ayo/pull/110 Refs: https://github.com/ayojs/ayo/pull/114 Refs: https://github.com/ayojs/ayo/pull/117 PR-URL: https://github.com/nodejs/node/pull/20876 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'test/parallel/test-worker-cleanup-handles.js')
-rw-r--r--test/parallel/test-worker-cleanup-handles.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/parallel/test-worker-cleanup-handles.js b/test/parallel/test-worker-cleanup-handles.js
new file mode 100644
index 0000000000..ba4f6aa51a
--- /dev/null
+++ b/test/parallel/test-worker-cleanup-handles.js
@@ -0,0 +1,30 @@
+// Flags: --experimental-worker
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const { Worker, isMainThread, parentPort } = require('worker');
+const { Server } = require('net');
+const fs = require('fs');
+
+if (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) => {
+ if (fd === -1) {
+ // This happens when server sockets don’t have file descriptors,
+ // i.e. on Windows.
+ return;
+ }
+ common.expectsError(() => fs.fstatSync(fd),
+ { code: 'EBADF' });
+ }));
+} else {
+ const server = new Server();
+ server.listen(0);
+ parentPort.postMessage(server._handle.fd);
+ server.unref();
+}