Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test,net: add tests for server.connections #10762

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,9 +1132,8 @@ function Server(options, connectionListener) {
return this._connections;
}, 'Server.connections property is deprecated. ' +
'Use Server.getConnections method instead.'),
set: internalUtil.deprecate((val) => {
return (this._connections = val);
}, 'Server.connections property is deprecated.'),
set: internalUtil.deprecate((val) => (this._connections = val),
'Server.connections property is deprecated.'),
configurable: true, enumerable: false
});

Expand Down
44 changes: 44 additions & 0 deletions test/parallel/test-net-server-connections-child-null.js
Original file line number Diff line number Diff line change
@@ -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);
}
7 changes: 4 additions & 3 deletions test/parallel/test-net-server-connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ const assert = require('assert');

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();

// 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(server.connections, 0);
Copy link
Member

@jasnell jasnell Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might also consider adding a check for the deprecation warning... e.g.

common.expectWarning('DeprecationWarning',
                     'Server.connections property is deprecated.');