Skip to content

Commit 7904066

Browse 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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 3919edb commit 7904066

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

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

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
'use strict';
2-
varcommon=require('../common');
3-
varassert=require('assert');
2+
constcommon=require('../common');
3+
constassert=require('assert');
44

5-
varnet=require('net');
5+
constnet=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-
varN=200;
12-
varcount=0;
11+
constN=20;
1312
varcloses=0;
14-
varwaits=[];
13+
constwaits=[];
1514

16-
varserver=net.createServer(function(connection){
17-
console.error('connect %d',count++);
15+
constserver=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
functionmakeConnection(index){
32-
varc=net.createConnection(server.address().port);
28+
constc=net.createConnection(server.address().port);
3329
vargotData=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)