test: use log only in test-child-process-fork-net
We are currently having issues with test-child-process-fork-net on Windows CI. Debugging is slightly hampered by the mix of `console.log()` and `console.error()` as our test runner does not interleave stdout and stderr, so the order of output is not preserved. Change the sole instance of `console.error()` to `console.log()` to improve debugability. While editing, I also took the opportunity to add capitalization and punctuation to comments (as that is a nit we see from time to time and there is a potential ESLint rule to enforce the capitalization part). PR-URL: https://github.com/nodejs/node/pull/20873 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
6e8abb13aa
commit
c82a9583ce
@ -25,7 +25,6 @@ const assert = require('assert');
|
|||||||
const fork = require('child_process').fork;
|
const fork = require('child_process').fork;
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
// progress tracker
|
|
||||||
function ProgressTracker(missing, callback) {
|
function ProgressTracker(missing, callback) {
|
||||||
this.missing = missing;
|
this.missing = missing;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
@ -54,7 +53,7 @@ if (process.argv[2] === 'child') {
|
|||||||
socket.destroy();
|
socket.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
// start making connection from parent
|
// Start making connection from parent.
|
||||||
console.log('CHILD: server listening');
|
console.log('CHILD: server listening');
|
||||||
process.send({ what: 'listening' });
|
process.send({ what: 'listening' });
|
||||||
});
|
});
|
||||||
@ -86,10 +85,10 @@ if (process.argv[2] === 'child') {
|
|||||||
assert.strictEqual(code, 0, message);
|
assert.strictEqual(code, 0, message);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// send net.Server to child and test by connecting
|
// Send net.Server to child and test by connecting.
|
||||||
function testServer(callback) {
|
function testServer(callback) {
|
||||||
|
|
||||||
// destroy server execute callback when done
|
// Destroy server execute callback when done.
|
||||||
const progress = new ProgressTracker(2, function() {
|
const progress = new ProgressTracker(2, function() {
|
||||||
server.on('close', function() {
|
server.on('close', function() {
|
||||||
console.log('PARENT: server closed');
|
console.log('PARENT: server closed');
|
||||||
@ -98,11 +97,11 @@ if (process.argv[2] === 'child') {
|
|||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
// we expect 4 connections and close events
|
// We expect 4 connections and close events.
|
||||||
const connections = new ProgressTracker(4, progress.done.bind(progress));
|
const connections = new ProgressTracker(4, progress.done.bind(progress));
|
||||||
const closed = new ProgressTracker(4, progress.done.bind(progress));
|
const closed = new ProgressTracker(4, progress.done.bind(progress));
|
||||||
|
|
||||||
// create server and send it to child
|
// Create server and send it to child.
|
||||||
const server = net.createServer();
|
const server = net.createServer();
|
||||||
server.on('connection', function(socket) {
|
server.on('connection', function(socket) {
|
||||||
console.log('PARENT: got connection');
|
console.log('PARENT: got connection');
|
||||||
@ -115,11 +114,11 @@ if (process.argv[2] === 'child') {
|
|||||||
});
|
});
|
||||||
server.listen(0);
|
server.listen(0);
|
||||||
|
|
||||||
// handle client messages
|
// Handle client messages.
|
||||||
function messageHandlers(msg) {
|
function messageHandlers(msg) {
|
||||||
|
|
||||||
if (msg.what === 'listening') {
|
if (msg.what === 'listening') {
|
||||||
// make connections
|
// Make connections.
|
||||||
let socket;
|
let socket;
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
socket = net.connect(server.address().port, function() {
|
socket = net.connect(server.address().port, function() {
|
||||||
@ -143,11 +142,11 @@ if (process.argv[2] === 'child') {
|
|||||||
child.on('message', messageHandlers);
|
child.on('message', messageHandlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
// send net.Socket to child
|
// Send net.Socket to child.
|
||||||
function testSocket(callback) {
|
function testSocket(callback) {
|
||||||
|
|
||||||
// create a new server and connect to it,
|
// Create a new server and connect to it,
|
||||||
// but the socket will be handled by the child
|
// but the socket will be handled by the child.
|
||||||
const server = net.createServer();
|
const server = net.createServer();
|
||||||
server.on('connection', function(socket) {
|
server.on('connection', function(socket) {
|
||||||
socket.on('close', function() {
|
socket.on('close', function() {
|
||||||
@ -159,14 +158,14 @@ if (process.argv[2] === 'child') {
|
|||||||
console.log('PARENT: server closed');
|
console.log('PARENT: server closed');
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
// don't listen on the same port, because SmartOS sometimes says
|
// Don't listen on the same port, because SmartOS sometimes says
|
||||||
// that the server's fd is closed, but it still cannot listen
|
// that the server's fd is closed, but it still cannot listen
|
||||||
// on the same port again.
|
// on the same port again.
|
||||||
//
|
//
|
||||||
// An isolated test for this would be lovely, but for now, this
|
// An isolated test for this would be lovely, but for now, this
|
||||||
// will have to do.
|
// will have to do.
|
||||||
server.listen(0, function() {
|
server.listen(0, function() {
|
||||||
console.error('testSocket, listening');
|
console.log('testSocket, listening');
|
||||||
const connect = net.connect(server.address().port);
|
const connect = net.connect(server.address().port);
|
||||||
let store = '';
|
let store = '';
|
||||||
connect.on('data', function(chunk) {
|
connect.on('data', function(chunk) {
|
||||||
@ -181,7 +180,7 @@ if (process.argv[2] === 'child') {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// create server and send it to child
|
// Create server and send it to child.
|
||||||
let serverSuccess = false;
|
let serverSuccess = false;
|
||||||
let socketSuccess = false;
|
let socketSuccess = false;
|
||||||
child.on('message', function onReady(msg) {
|
child.on('message', function onReady(msg) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user