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>
This commit is contained in:
parent
66f09be743
commit
97f001ab16
@ -1132,9 +1132,8 @@ function Server(options, connectionListener) {
|
|||||||
return this._connections;
|
return this._connections;
|
||||||
}, 'Server.connections property is deprecated. ' +
|
}, 'Server.connections property is deprecated. ' +
|
||||||
'Use Server.getConnections method instead.'),
|
'Use Server.getConnections method instead.'),
|
||||||
set: internalUtil.deprecate((val) => {
|
set: internalUtil.deprecate((val) => (this._connections = val),
|
||||||
return (this._connections = val);
|
'Server.connections property is deprecated.'),
|
||||||
}, 'Server.connections property is deprecated.'),
|
|
||||||
configurable: true, enumerable: false
|
configurable: true, enumerable: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
44
test/parallel/test-net-server-connections-child-null.js
Normal file
44
test/parallel/test-net-server-connections-child-null.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
'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);
|
||||||
|
}
|
@ -1,12 +1,18 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
// test that server.connections property is no longer enumerable now that it
|
|
||||||
// has been marked as deprecated
|
|
||||||
|
|
||||||
const server = new net.Server();
|
const server = new net.Server();
|
||||||
|
|
||||||
|
const expectedWarning = 'Server.connections property is deprecated. ' +
|
||||||
|
'Use Server.getConnections method instead.';
|
||||||
|
|
||||||
|
common.expectWarning('DeprecationWarning', expectedWarning);
|
||||||
|
|
||||||
|
// test that server.connections property is no longer enumerable now that it
|
||||||
|
// has been marked as deprecated
|
||||||
assert.strictEqual(Object.keys(server).indexOf('connections'), -1);
|
assert.strictEqual(Object.keys(server).indexOf('connections'), -1);
|
||||||
|
|
||||||
|
assert.strictEqual(server.connections, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user