1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
3
- var assert = require ( 'assert' ) ;
2
+ const common = require ( '../common' ) ;
3
+ const assert = require ( 'assert' ) ;
4
4
5
- var net = require ( 'net' ) ;
5
+ const net = require ( 'net' ) ;
6
6
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.
10
10
11
- var N = 200 ;
12
- var count = 0 ;
11
+ const N = 20 ;
13
12
var closes = 0 ;
14
- var waits = [ ] ;
13
+ const waits = [ ] ;
15
14
16
- var server = net . createServer ( function ( connection ) {
17
- console . error ( 'connect %d' , count ++ ) ;
15
+ const server = net . createServer ( common . mustCall ( function ( connection ) {
18
16
connection . write ( 'hello' ) ;
19
17
waits . push ( function ( ) { connection . end ( ) ; } ) ;
20
- } ) ;
18
+ } , N / 2 ) ) ;
21
19
22
20
server . listen ( 0 , function ( ) {
23
21
makeConnection ( 0 ) ;
24
22
} ) ;
25
23
26
24
server . maxConnections = N / 2 ;
27
25
28
- console . error ( 'server.maxConnections = %d' , server . maxConnections ) ;
29
-
30
26
31
27
function makeConnection ( index ) {
32
- var c = net . createConnection ( server . address ( ) . port ) ;
28
+ const c = net . createConnection ( server . address ( ) . port ) ;
33
29
var gotData = false ;
34
30
35
31
c . on ( 'connect' , function ( ) {
@@ -42,10 +38,10 @@ function makeConnection(index) {
42
38
closes ++ ;
43
39
44
40
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
+ ) ;
49
45
}
50
46
51
47
if ( closes === N / 2 ) {
@@ -58,11 +54,11 @@ function makeConnection(index) {
58
54
}
59
55
60
56
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` ) ;
63
59
} 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` ) ;
66
62
}
67
63
} ) ;
68
64
} ) ;
@@ -86,5 +82,5 @@ function makeConnection(index) {
86
82
87
83
88
84
process . on ( 'exit' , function ( ) {
89
- assert . equal ( N , closes ) ;
85
+ assert . strictEqual ( N , closes ) ;
90
86
} ) ;
0 commit comments