Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4514fd7

Browse filesBrowse 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 f301df4 commit 4514fd7
Copy full SHA for 4514fd7

File tree

Expand file treeCollapse file tree

1 file changed

+25
-25
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-25
lines changed
Open diff view settings
Collapse file
+25-25Lines changed: 25 additions & 25 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.