0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-net-server-connections-child-null.js
Rich Trott 97f001ab16 test,net: add tests for server.connections
There were no tests confirming situations where server.connections
should return `null`. Add a test for that situation.

Expand existing server.connection test slightly to check value.

Refactor (mostly spacing) code for server.connections setter.

PR-URL: https://github.com/nodejs/node/pull/10762
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-01-14 20:57:26 -08:00

45 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fork = require('child_process').fork;
const net = require('net');
if (process.argv[2] === 'child') {
process.on('message', (msg, socket) => {
socket.end('goodbye');
});
process.send('hello');
} else {
const child = fork(process.argv[1], ['child']);
const runTest = common.mustCall(() => {
const server = net.createServer();
// server.connections should start as 0
assert.strictEqual(server.connections, 0);
server.on('connection', (socket) => {
child.send({what: 'socket'}, socket);
});
server.on('close', () => {
child.kill();
});
server.listen(0, common.mustCall(() => {
const connect = net.connect(server.address().port);
connect.on('close', common.mustCall(() => {
// now server.connections should be null
assert.strictEqual(server.connections, null);
server.close();
}));
}));
});
child.on('message', runTest);
}