Skip to content

Commit 529f000

Browse files
committed
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. Fixes: #17589
1 parent 7bb2cc4 commit 529f000

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

test/sequential/test-child-process-pass-fd.js

+32-16
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,42 @@ const fork = require('child_process').fork;
99
const net = require('net');
1010

1111
const N = 80;
12+
let messageCallbackCount = 0;
13+
14+
function forkWorker() {
15+
const messageCallback = (msg, handle) => {
16+
messageCallbackCount++;
17+
assert.strictEqual(msg, 'handle');
18+
assert.ok(handle);
19+
worker.send('got');
20+
21+
let recvData = '';
22+
handle.on('data', common.mustCall((data) => {
23+
recvData += data;
24+
}));
25+
26+
handle.on('end', () => {
27+
assert.strictEqual(recvData, 'hello');
28+
worker.kill();
29+
});
30+
};
31+
32+
const worker = fork(__filename, ['child']);
33+
worker.on('error', (err) => {
34+
if (/\bEAGAIN\b/.test(err.message)) {
35+
forkWorker();
36+
return;
37+
}
38+
throw err;
39+
});
40+
worker.once('message', messageCallback);
41+
}
1242

1343
if (process.argv[2] !== 'child') {
1444
for (let i = 0; i < N; ++i) {
15-
const worker = fork(__filename, ['child']);
16-
worker.once('message', common.mustCall((msg, handle) => {
17-
assert.strictEqual(msg, 'handle');
18-
assert.ok(handle);
19-
worker.send('got');
20-
21-
let recvData = '';
22-
handle.on('data', common.mustCall((data) => {
23-
recvData += data;
24-
}));
25-
26-
handle.on('end', () => {
27-
assert.strictEqual(recvData, 'hello');
28-
worker.kill();
29-
});
30-
}));
45+
forkWorker();
3146
}
47+
process.on('exit', () => { assert.strictEqual(messageCallbackCount, N); });
3248
} else {
3349
let socket;
3450
let cbcalls = 0;

0 commit comments

Comments
 (0)