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.

Fixes: #17589
  • Loading branch information
Trott committed Dec 11, 2017
1 parent 7bb2cc4 commit 529f000
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 @@ -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

0 comments on commit 529f000

Please sign in to comment.