GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: fix flaky test-child-process-pass-fd · nodejs/node@fb0bd8a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/sequential
    • test-child-process-pass-fd.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/sequential/test-child-process-pass-fd.js
+32-16Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,42 @@ const { fork } = require('child_process');
1818
const net = require('net');
1919

2020
const N = 80;
21+
let messageCallbackCount = 0;
2122

22-
if (process.argv[2] !== 'child') {
23-
for (let i = 0; i < N; ++i) {
24-
const worker = fork(__filename, ['child']);
25-
worker.once('message', common.mustCall((msg, handle) => {
26-
assert.strictEqual(msg, 'handle');
27-
assert.ok(handle);
28-
worker.send('got');
29-
30-
let recvData = '';
31-
handle.on('data', common.mustCall((data) => {
32-
recvData += data;
33-
}));
23+
function forkWorker() {
24+
const messageCallback = (msg, handle) => {
25+
messageCallbackCount++;
26+
assert.strictEqual(msg, 'handle');
27+
assert.ok(handle);
28+
worker.send('got');
3429

35-
handle.on('end', () => {
36-
assert.strictEqual(recvData, 'hello');
37-
worker.kill();
38-
});
30+
let recvData = '';
31+
handle.on('data', common.mustCall((data) => {
32+
recvData += data;
3933
}));
34+
35+
handle.on('end', () => {
36+
assert.strictEqual(recvData, 'hello');
37+
worker.kill();
38+
});
39+
};
40+
41+
const worker = fork(__filename, ['child']);
42+
worker.on('error', (err) => {
43+
if (/\bEAGAIN\b/.test(err.message)) {
44+
forkWorker();
45+
return;
46+
}
47+
throw err;
48+
});
49+
worker.once('message', messageCallback);
50+
}
51+
52+
if (process.argv[2] !== 'child') {
53+
for (let i = 0; i < N; ++i) {
54+
forkWorker();
4055
}
56+
process.on('exit', () => { assert.strictEqual(messageCallbackCount, N); });
4157
} else {
4258
let socket;
4359
let cbcalls = 0;

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.