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 7904066

Browse filesBrowse files
TrottMyles Borins
authored andcommitted
test: refactor test-net-server-max-connections
The test timed out on Windows in CI. Made the following changes: * reduced total connections from 200 to 20 * var -> const * string concatenation -> templates * assert.equal -> assert.strictEqual PR-URL: #8931 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 3919edb commit 7904066
Copy full SHA for 7904066

File tree

Expand file treeCollapse file tree

1 file changed

+20
-24
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-24
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-net-server-max-connections.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-net-server-max-connections.js
+20-24Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
3+
const assert = require('assert');
44

5-
var net = require('net');
5+
const net = require('net');
66

7-
// This test creates 200 connections to a server and sets the server's
8-
// maxConnections property to 100. The first 100 connections make it through
9-
// and the last 100 connections are rejected.
7+
// This test creates 20 connections to a server and sets the server's
8+
// maxConnections property to 10. The first 10 connections make it through
9+
// and the last 10 connections are rejected.
1010

11-
var N = 200;
12-
var count = 0;
11+
const N = 20;
1312
var closes = 0;
14-
var waits = [];
13+
const waits = [];
1514

16-
var server = net.createServer(function(connection) {
17-
console.error('connect %d', count++);
15+
const server = net.createServer(common.mustCall(function(connection) {
1816
connection.write('hello');
1917
waits.push(function() { connection.end(); });
20-
});
18+
}, N / 2));
2119

2220
server.listen(0, function() {
2321
makeConnection(0);
2422
});
2523

2624
server.maxConnections = N / 2;
2725

28-
console.error('server.maxConnections = %d', server.maxConnections);
29-
3026

3127
function makeConnection(index) {
32-
var c = net.createConnection(server.address().port);
28+
const c = net.createConnection(server.address().port);
3329
var gotData = false;
3430

3531
c.on('connect', function() {
@@ -42,10 +38,10 @@ function makeConnection(index) {
4238
closes++;
4339

4440
if (closes < N / 2) {
45-
assert.ok(server.maxConnections <= index,
46-
index +
47-
' was one of the first closed connections ' +
48-
'but shouldnt have been');
41+
assert.ok(
42+
server.maxConnections <= index,
43+
`${index} should not have been one of the first closed connections`
44+
);
4945
}
5046

5147
if (closes === N / 2) {
@@ -58,11 +54,11 @@ function makeConnection(index) {
5854
}
5955

6056
if (index < server.maxConnections) {
61-
assert.equal(true, gotData,
62-
index + ' didn\'t get data, but should have');
57+
assert.strictEqual(true, gotData,
58+
`${index} didn't get data, but should have`);
6359
} else {
64-
assert.equal(false, gotData,
65-
index + ' got data, but shouldn\'t have');
60+
assert.strictEqual(false, gotData,
61+
`${index} got data, but shouldn't have`);
6662
}
6763
});
6864
});
@@ -86,5 +82,5 @@ function makeConnection(index) {
8682

8783

8884
process.on('exit', function() {
89-
assert.equal(N, closes);
85+
assert.strictEqual(N, closes);
9086
});

0 commit comments

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