From fcc5b9915272ffd8532f92ea06864354a8ca67cf Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 10 Dec 2017 18:47:48 -0800 Subject: [PATCH] test: fix flaky test-child-process-pass-fd 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: https://github.com/nodejs/node/pull/17598 Fixes: https://github.com/nodejs/node/issues/17589 Reviewed-By: Santiago Gimeno Reviewed-By: Gibson Fahnestock Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Gireesh Punathil --- test/sequential/test-child-process-pass-fd.js | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/test/sequential/test-child-process-pass-fd.js b/test/sequential/test-child-process-pass-fd.js index 73e469cdede2be..98832c57a3df67 100644 --- a/test/sequential/test-child-process-pass-fd.js +++ b/test/sequential/test-child-process-pass-fd.js @@ -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;