Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 33af09f

Browse filesBrowse files
TrottItalo A. Casas
authored andcommitted
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: #10762 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d751afa commit 33af09f
Copy full SHA for 33af09f

File tree

Expand file treeCollapse file tree

3 files changed

+56
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+56
-7
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,9 +1132,8 @@ function Server(options, connectionListener) {
11321132
return this._connections;
11331133
}, 'Server.connections property is deprecated. ' +
11341134
'Use Server.getConnections method instead.'),
1135-
set: internalUtil.deprecate((val) => {
1136-
return (this._connections = val);
1137-
}, 'Server.connections property is deprecated.'),
1135+
set: internalUtil.deprecate((val) => (this._connections = val),
1136+
'Server.connections property is deprecated.'),
11381137
configurable: true, enumerable: false
11391138
});
11401139

Collapse file
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const fork = require('child_process').fork;
5+
const net = require('net');
6+
7+
if (process.argv[2] === 'child') {
8+
9+
process.on('message', (msg, socket) => {
10+
socket.end('goodbye');
11+
});
12+
13+
process.send('hello');
14+
15+
} else {
16+
17+
const child = fork(process.argv[1], ['child']);
18+
19+
const runTest = common.mustCall(() => {
20+
21+
const server = net.createServer();
22+
23+
// server.connections should start as 0
24+
assert.strictEqual(server.connections, 0);
25+
server.on('connection', (socket) => {
26+
child.send({what: 'socket'}, socket);
27+
});
28+
server.on('close', () => {
29+
child.kill();
30+
});
31+
32+
server.listen(0, common.mustCall(() => {
33+
const connect = net.connect(server.address().port);
34+
35+
connect.on('close', common.mustCall(() => {
36+
// now server.connections should be null
37+
assert.strictEqual(server.connections, null);
38+
server.close();
39+
}));
40+
}));
41+
});
42+
43+
child.on('message', runTest);
44+
}
Collapse file
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44

55
const net = require('net');
66

7-
// test that server.connections property is no longer enumerable now that it
8-
// has been marked as deprecated
9-
107
const server = new net.Server();
118

9+
const expectedWarning = 'Server.connections property is deprecated. ' +
10+
'Use Server.getConnections method instead.';
11+
12+
common.expectWarning('DeprecationWarning', expectedWarning);
13+
14+
// test that server.connections property is no longer enumerable now that it
15+
// has been marked as deprecated
1216
assert.strictEqual(Object.keys(server).indexOf('connections'), -1);
17+
18+
assert.strictEqual(server.connections, 0);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.