Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions test/sequential/test-child-process-pass-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,42 @@ const fork = require('child_process').fork;
const net = require('net');

const N = 80;
let messageCallbackCount = 0;

function forkWorker() {
const messageCallback = (msg, handle) => {
messageCallbackCount++;
assert.strictEqual(msg, 'handle');
assert.ok(handle);
worker.send('got');

let recvData = '';
handle.on('data', common.mustCall((data) => {
recvData += data;
}));

handle.on('end', () => {
assert.strictEqual(recvData, 'hello');
worker.kill();
});
};

const worker = fork(__filename, ['child']);
worker.on('error', (err) => {
if (/\bEAGAIN\b/.test(err.message)) {
forkWorker();
return;
}
throw err;
});
worker.once('message', messageCallback);
}

if (process.argv[2] !== 'child') {
for (let i = 0; i < N; ++i) {
const worker = fork(__filename, ['child']);
worker.once('message', common.mustCall((msg, handle) => {
assert.strictEqual(msg, 'handle');
assert.ok(handle);
worker.send('got');

let recvData = '';
handle.on('data', common.mustCall((data) => {
recvData += data;
}));

handle.on('end', () => {
assert.strictEqual(recvData, 'hello');
worker.kill();
});
}));
forkWorker();
}
process.on('exit', () => { assert.strictEqual(messageCallbackCount, N); });
} else {
let socket;
let cbcalls = 0;
Expand Down