Skip to content

Commit e7ae8eb

Browse files
TrottMylesBorins
authored andcommitted
test: refactor test-child-process-pass-fd
Add a comment explaining the test (especailly why it forks 80 processes. Use destructuring and an arrow function callback. PR-URL: #17596 Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 5a9172f commit e7ae8eb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
'use strict';
22
const common = require('../common');
3+
4+
// On some OS X versions, when passing fd's between processes:
5+
// When the handle associated to a specific file descriptor is closed by the
6+
// sender process before it's received in the destination, the handle is indeed
7+
// closed while it should remain opened. In order to fix this behavior, don't
8+
// close the handle until the `NODE_HANDLE_ACK` is received by the sender.
9+
// This test is basically `test-cluster-net-send` but creating lots of workers
10+
// so the issue reproduces on OS X consistently.
11+
312
if ((process.config.variables.arm_version === '6') ||
413
(process.config.variables.arm_version === '7'))
514
common.skip('Too slow for armv6 and armv7 bots');
615

716
const assert = require('assert');
8-
const fork = require('child_process').fork;
17+
const { fork } = require('child_process');
918
const net = require('net');
1019

1120
const N = 80;
@@ -46,14 +55,14 @@ if (process.argv[2] !== 'child') {
4655
process.on('message', common.mustCall());
4756

4857
const server = net.createServer((c) => {
49-
process.once('message', function(msg) {
58+
process.once('message', (msg) => {
5059
assert.strictEqual(msg, 'got');
5160
c.end('hello');
5261
});
5362
socketConnected();
5463
}).unref();
5564
server.listen(0, common.localhostIPv4, () => {
56-
const port = server.address().port;
65+
const { port } = server.address();
5766
socket = net.connect(port, common.localhostIPv4, socketConnected).unref();
5867
});
5968
}

0 commit comments

Comments
 (0)