@@ -12,8 +12,8 @@ if (common.isWindows) {
12
12
return ;
13
13
}
14
14
15
- var body = 'hello world\n' ;
16
- var server = http . createServer ( function ( req , res ) {
15
+ const body = 'hello world\n' ;
16
+ const server = http . createServer ( function ( req , res ) {
17
17
res . writeHead ( 200 , {
18
18
'Content-Length' : body . length ,
19
19
'Content-Type' : 'text/plain'
@@ -22,12 +22,12 @@ var server = http.createServer(function(req, res) {
22
22
res . end ( ) ;
23
23
} ) ;
24
24
25
- var keepAliveReqSec = 0 ;
26
- var normalReqSec = 0 ;
25
+ let keepAliveReqSec = 0 ;
26
+ let normalReqSec = 0 ;
27
27
28
28
29
29
function runAb ( opts , callback ) {
30
- var args = [
30
+ const args = [
31
31
'-c' , opts . concurrent || 100 ,
32
32
'-t' , opts . threads || 2 ,
33
33
'-d' , opts . duration || '10s' ,
@@ -41,13 +41,11 @@ function runAb(opts, callback) {
41
41
args . push ( url . format ( { hostname : '127.0.0.1' ,
42
42
port : common . PORT , protocol : 'http' } ) ) ;
43
43
44
- //console.log(comm, args.join(' '));
45
-
46
- var child = spawn ( 'wrk' , args ) ;
44
+ const child = spawn ( 'wrk' , args ) ;
47
45
child . stderr . pipe ( process . stderr ) ;
48
46
child . stdout . setEncoding ( 'utf8' ) ;
49
47
50
- var stdout ;
48
+ let stdout ;
51
49
52
50
child . stdout . on ( 'data' , function ( data ) {
53
51
stdout += data ;
@@ -60,11 +58,11 @@ function runAb(opts, callback) {
60
58
return ;
61
59
}
62
60
63
- var matches = / R e q u e s t s \/ s e c : \s * ( \d + ) \. / mi. exec ( stdout ) ;
64
- var reqSec = parseInt ( matches [ 1 ] ) ;
61
+ let matches = / R e q u e s t s \/ s e c : \s * ( \d + ) \. / mi. exec ( stdout ) ;
62
+ const reqSec = parseInt ( matches [ 1 ] ) ;
65
63
66
64
matches = / K e e p - A l i v e r e q u e s t s : \s * ( \d + ) / mi. exec ( stdout ) ;
67
- var keepAliveRequests ;
65
+ let keepAliveRequests ;
68
66
if ( matches ) {
69
67
keepAliveRequests = parseInt ( matches [ 1 ] ) ;
70
68
} else {
@@ -75,21 +73,19 @@ function runAb(opts, callback) {
75
73
} ) ;
76
74
}
77
75
78
- server . listen ( common . PORT , function ( ) {
79
- runAb ( { keepalive : true } , function ( reqSec ) {
76
+ server . listen ( common . PORT , ( ) => {
77
+ runAb ( { keepalive : true } , ( reqSec ) => {
80
78
keepAliveReqSec = reqSec ;
81
- console . log ( 'keep-alive:' , keepAliveReqSec , 'req/sec' ) ;
82
79
83
80
runAb ( { keepalive : false } , function ( reqSec ) {
84
81
normalReqSec = reqSec ;
85
- console . log ( 'normal:' + normalReqSec + ' req/sec' ) ;
86
82
server . close ( ) ;
87
83
} ) ;
88
84
} ) ;
89
85
} ) ;
90
86
91
87
process . on ( 'exit' , function ( ) {
92
- assert . equal ( true , normalReqSec > 50 ) ;
93
- assert . equal ( true , keepAliveReqSec > 50 ) ;
94
- assert . equal ( true , normalReqSec < keepAliveReqSec ) ;
88
+ assert . strictEqual ( true , normalReqSec > 50 ) ;
89
+ assert . strictEqual ( true , keepAliveReqSec > 50 ) ;
90
+ assert . strictEqual ( true , normalReqSec < keepAliveReqSec ) ;
95
91
} ) ;
0 commit comments