Skip to content

Commit 0e89941

Browse files
edsadrMylesBorins
authored andcommitted
test: refactor the code in test-http-keep-alive
* use common.mustCall to control the functions execution automatically * use let and const instead of var * use assert.strictEqual instead assert.equal PR-URL: #10350 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com>
1 parent ec587bc commit 0e89941

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

test/parallel/test-http-keep-alive.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
'use strict';
2-
require('../common');
3-
var assert = require('assert');
4-
var http = require('http');
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
55

6-
var body = 'hello world\n';
6+
const server = http.createServer(common.mustCall((req, res) => {
7+
const body = 'hello world\n';
78

8-
var server = http.createServer(function(req, res) {
99
res.writeHead(200, {'Content-Length': body.length});
1010
res.write(body);
1111
res.end();
12-
});
12+
}, 3));
1313

14-
var agent = new http.Agent({maxSockets: 1});
15-
var headers = {'connection': 'keep-alive'};
16-
var name;
14+
const agent = new http.Agent({maxSockets: 1});
15+
const headers = {'connection': 'keep-alive'};
16+
let name;
1717

18-
server.listen(0, function() {
18+
server.listen(0, common.mustCall(function() {
1919
name = agent.getName({ port: this.address().port });
2020
http.get({
2121
path: '/', headers: headers, port: this.address().port, agent: agent
22-
}, function(response) {
23-
assert.equal(agent.sockets[name].length, 1);
24-
assert.equal(agent.requests[name].length, 2);
22+
}, common.mustCall((response) => {
23+
assert.strictEqual(agent.sockets[name].length, 1);
24+
assert.strictEqual(agent.requests[name].length, 2);
2525
response.resume();
26-
});
26+
}));
2727

2828
http.get({
2929
path: '/', headers: headers, port: this.address().port, agent: agent
30-
}, function(response) {
31-
assert.equal(agent.sockets[name].length, 1);
32-
assert.equal(agent.requests[name].length, 1);
30+
}, common.mustCall((response) => {
31+
assert.strictEqual(agent.sockets[name].length, 1);
32+
assert.strictEqual(agent.requests[name].length, 1);
3333
response.resume();
34-
});
34+
}));
3535

3636
http.get({
3737
path: '/', headers: headers, port: this.address().port, agent: agent
38-
}, function(response) {
39-
response.on('end', function() {
40-
assert.equal(agent.sockets[name].length, 1);
38+
}, common.mustCall((response) => {
39+
response.on('end', common.mustCall(() => {
40+
assert.strictEqual(agent.sockets[name].length, 1);
4141
assert(!agent.requests.hasOwnProperty(name));
4242
server.close();
43-
});
43+
}));
4444
response.resume();
45-
});
46-
});
45+
}));
46+
}));
4747

48-
process.on('exit', function() {
48+
process.on('exit', () => {
4949
assert(!agent.sockets.hasOwnProperty(name));
5050
assert(!agent.requests.hasOwnProperty(name));
5151
});

0 commit comments

Comments
 (0)