Skip to content

Commit f86c64a

Browse files
sivaprsMylesBorins
authored andcommitted
test: refactor the code of test-keep-alive.js
* use const and let instead of var * use assert.strictEqual instead of assert.equal * use arrow functions * removed console.log statements PR-URL: #10684 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent 4d51db8 commit f86c64a

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

test/pummel/test-keep-alive.js

+15-19
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ if (common.isWindows) {
1212
return;
1313
}
1414

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) {
1717
res.writeHead(200, {
1818
'Content-Length': body.length,
1919
'Content-Type': 'text/plain'
@@ -22,12 +22,12 @@ var server = http.createServer(function(req, res) {
2222
res.end();
2323
});
2424

25-
var keepAliveReqSec = 0;
26-
var normalReqSec = 0;
25+
let keepAliveReqSec = 0;
26+
let normalReqSec = 0;
2727

2828

2929
function runAb(opts, callback) {
30-
var args = [
30+
const args = [
3131
'-c', opts.concurrent || 100,
3232
'-t', opts.threads || 2,
3333
'-d', opts.duration || '10s',
@@ -41,13 +41,11 @@ function runAb(opts, callback) {
4141
args.push(url.format({ hostname: '127.0.0.1',
4242
port: common.PORT, protocol: 'http'}));
4343

44-
//console.log(comm, args.join(' '));
45-
46-
var child = spawn('wrk', args);
44+
const child = spawn('wrk', args);
4745
child.stderr.pipe(process.stderr);
4846
child.stdout.setEncoding('utf8');
4947

50-
var stdout;
48+
let stdout;
5149

5250
child.stdout.on('data', function(data) {
5351
stdout += data;
@@ -60,11 +58,11 @@ function runAb(opts, callback) {
6058
return;
6159
}
6260

63-
var matches = /Requests\/sec:\s*(\d+)\./mi.exec(stdout);
64-
var reqSec = parseInt(matches[1]);
61+
let matches = /Requests\/sec:\s*(\d+)\./mi.exec(stdout);
62+
const reqSec = parseInt(matches[1]);
6563

6664
matches = /Keep-Alive requests:\s*(\d+)/mi.exec(stdout);
67-
var keepAliveRequests;
65+
let keepAliveRequests;
6866
if (matches) {
6967
keepAliveRequests = parseInt(matches[1]);
7068
} else {
@@ -75,21 +73,19 @@ function runAb(opts, callback) {
7573
});
7674
}
7775

78-
server.listen(common.PORT, function() {
79-
runAb({ keepalive: true }, function(reqSec) {
76+
server.listen(common.PORT, () => {
77+
runAb({ keepalive: true }, (reqSec) => {
8078
keepAliveReqSec = reqSec;
81-
console.log('keep-alive:', keepAliveReqSec, 'req/sec');
8279

8380
runAb({ keepalive: false }, function(reqSec) {
8481
normalReqSec = reqSec;
85-
console.log('normal:' + normalReqSec + ' req/sec');
8682
server.close();
8783
});
8884
});
8985
});
9086

9187
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);
9591
});

0 commit comments

Comments
 (0)