aboutsummaryrefslogtreecommitdiff
path: root/test/sequential
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2018-03-12 20:02:33 -0700
committerRich Trott <rtrott@gmail.com>2018-03-14 22:28:18 -0700
commit5e23b65a87e0eb47f5dc09c2720e46cb4d6f6411 (patch)
tree517cbfb86e8db214685cd9c0229cc66a07e00df1 /test/sequential
parenta2c0fcc0d8bc9bd4559089f1182b13a2ae7bb318 (diff)
downloadandroid-node-v8-5e23b65a87e0eb47f5dc09c2720e46cb4d6f6411.tar.gz
android-node-v8-5e23b65a87e0eb47f5dc09c2720e46cb4d6f6411.tar.bz2
android-node-v8-5e23b65a87e0eb47f5dc09c2720e46cb4d6f6411.zip
test: fix test-cluster-send-handle-large-payload
test-cluster-send-handle-large-payload is susceptible to failure if it is competing for resources. Move to `sequential` directory so it is not competing with other tests. Fixes: https://github.com/nodejs/node/issues/14844 PR-URL: https://github.com/nodejs/node/pull/19311 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'test/sequential')
-rw-r--r--test/sequential/test-cluster-send-handle-large-payload.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/sequential/test-cluster-send-handle-large-payload.js b/test/sequential/test-cluster-send-handle-large-payload.js
new file mode 100644
index 0000000000..f0ffa63421
--- /dev/null
+++ b/test/sequential/test-cluster-send-handle-large-payload.js
@@ -0,0 +1,54 @@
+'use strict';
+const common = require('../common');
+
+const assert = require('assert');
+const cluster = require('cluster');
+const net = require('net');
+
+const payload = 'a'.repeat(800004);
+
+if (cluster.isMaster) {
+ const server = net.createServer();
+
+ server.on('connection', common.mustCall((socket) => { socket.unref(); }));
+
+ const worker = cluster.fork();
+ worker.on('message', common.mustCall(({ payload: received }, handle) => {
+ assert.strictEqual(payload, received);
+ assert(handle instanceof net.Socket);
+ server.close();
+ handle.destroy();
+ }));
+
+ server.listen(0, common.mustCall(() => {
+ const port = server.address().port;
+ const socket = new net.Socket();
+ socket.connect(port, (err) => {
+ assert.ifError(err);
+ worker.send({ payload }, socket);
+ });
+ }));
+} else {
+ process.on('message', common.mustCall(({ payload: received }, handle) => {
+ assert.strictEqual(payload, received);
+ assert(handle instanceof net.Socket);
+
+ // On macOS, the parent process might not receive a message if it is sent
+ // to soon, and then subsequent messages are also sometimes not received.
+ //
+ // (Is this a bug or expected operating system behavior like the way a file
+ // watcher is returned before it's actually watching the file system on
+ // macOS?)
+ //
+ // Send a second message after a delay on macOS.
+ //
+ // Refs: https://github.com/nodejs/node/issues/14747
+ if (common.isOSX)
+ setTimeout(() => { process.send({ payload }, handle); }, 1000);
+ else
+ process.send({ payload }, handle);
+
+ // Prepare for a clean exit.
+ process.channel.unref();
+ }));
+}