Skip to content

Commit 4514fd7

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 f301df4 commit 4514fd7

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
'use strict';
2-
require('../common');
3-
varassert=require('assert');
4-
varhttp=require('http');
2+
constcommon=require('../common');
3+
constassert=require('assert');
4+
consthttp=require('http');
55

6-
varbody='hello world\n';
6+
constserver=http.createServer(common.mustCall((req,res)=>{
7+
constbody='hello world\n';
78

8-
varserver=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-
varagent=newhttp.Agent({maxSockets: 1});
15-
varheaders={'connection': 'keep-alive'};
16-
varname;
14+
constagent=newhttp.Agent({maxSockets: 1});
15+
constheaders={'connection': 'keep-alive'};
16+
letname;
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)