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 ;
1312var 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
2220server . listen ( 0 , function ( ) {
2321 makeConnection ( 0 ) ;
2422} ) ;
2523
2624server . maxConnections = N / 2 ;
2725
28- console . error ( 'server.maxConnections = %d' , server . maxConnections ) ;
29-
3026
3127function 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
8884process . on ( 'exit' , function ( ) {
89- assert . equal ( N , closes ) ;
85+ assert . strictEqual ( N , closes ) ;
9086} ) ;
0 commit comments