Skip to content

Commit

Permalink
test: fix flaky test-child-process-pass-fd
Browse files Browse the repository at this point in the history
test-child-process-pass-fd needs to launch many processes
simultaneously. On Fedora 24, this can result in EAGAIN "Resource
temporarily unavailable" errors. When this occurs, simply try to launch
a worker again.

PR-URL: #17598
Fixes: #17589
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
Trott authored and MylesBorins committed Jan 22, 2018
1 parent 2d4d9aa commit a304206
Showing 1 changed file with 32 additions and 16 deletions.
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 @@ -18,26 +18,42 @@ const { fork } = require('child_process');
const net = require('net');

const N = 80;
let messageCallbackCount = 0;

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;
}));
function forkWorker() {
const messageCallback = (msg, handle) => {
messageCallbackCount++;
assert.strictEqual(msg, 'handle');
assert.ok(handle);
worker.send('got');

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

0 comments on commit a304206

Please sign in to comment.