mirror of
https://github.com/nodejs/node.git
synced 2024-11-25 08:19:38 +01:00
2d2986ae72
* Make common.skip() exit. Also add common.printSkipMessage() for partial skips. * Don't make needless things before skip PR-URL: https://github.com/nodejs/node/pull/14021 Fixes: https://github.com/nodejs/node/issues/14016 Reviewed-By: Refael Ackermann <refack@gmail.com>
60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if ((process.config.variables.arm_version === '6') ||
|
|
(process.config.variables.arm_version === '7'))
|
|
common.skip('Too slow for armv6 and armv7 bots');
|
|
|
|
const assert = require('assert');
|
|
const fork = require('child_process').fork;
|
|
const net = require('net');
|
|
|
|
const N = 80;
|
|
|
|
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();
|
|
});
|
|
}));
|
|
}
|
|
} else {
|
|
let socket;
|
|
let cbcalls = 0;
|
|
function socketConnected() {
|
|
if (++cbcalls === 2)
|
|
process.send('handle', socket);
|
|
}
|
|
|
|
// As a side-effect, listening for the message event will ref the IPC channel,
|
|
// so the child process will stay alive as long as it has a parent process/IPC
|
|
// channel. Once this is done, we can unref our client and server sockets, and
|
|
// the only thing keeping this worker alive will be IPC. This is important,
|
|
// because it means a worker with no parent will have no referenced handles,
|
|
// thus no work to do, and will exit immediately, preventing process leaks.
|
|
process.on('message', common.mustCall());
|
|
|
|
const server = net.createServer((c) => {
|
|
process.once('message', function(msg) {
|
|
assert.strictEqual(msg, 'got');
|
|
c.end('hello');
|
|
});
|
|
socketConnected();
|
|
}).unref();
|
|
server.listen(0, common.localhostIPv4, () => {
|
|
const port = server.address().port;
|
|
socket = net.connect(port, common.localhostIPv4, socketConnected).unref();
|
|
});
|
|
}
|