Skip to content

Commit a40b0cb

Browse files
santigimenoMyles Borins
authored andcommitted
test: refactor http-end-throw-socket-handling
Remove timer to avoid the test timing out occasionally. PR-URL: #5676 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
1 parent 3f75751 commit a40b0cb

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
11
'use strict';
2-
varcommon=require('../common');
3-
varassert=require('assert');
2+
constcommon=require('../common');
3+
constassert=require('assert');
44

55
// Make sure that throwing in 'end' handler doesn't lock
66
// up the socket forever.
77
//
88
// This is NOT a good way to handle errors in general, but all
99
// the same, we should not be so brittle and easily broken.
1010

11-
varhttp=require('http');
11+
consthttp=require('http');
1212

13-
varn=0;
14-
varserver=http.createServer(function(req,res){
13+
letn=0;
14+
constserver=http.createServer((req,res)=>{
1515
if(++n===10)server.close();
1616
res.end('ok');
1717
});
1818

19-
server.listen(common.PORT,function(){
20-
for(vari=0;i<10;i++){
21-
varoptions={port: common.PORT};
22-
23-
varreq=http.request(options,function(res){
19+
server.listen(common.PORT,common.mustCall(()=>{
20+
for(leti=0;i<10;i++){
21+
constoptions={port: common.PORT};
22+
constreq=http.request(options,(res)=>{
2423
res.resume();
25-
res.on('end',function(){
24+
res.on('end',common.mustCall(()=>{
2625
thrownewError('gleep glorp');
27-
});
26+
}));
2827
});
2928
req.end();
3029
}
31-
});
30+
}));
3231

33-
setTimeout(function(){
34-
process.removeListener('uncaughtException',catcher);
35-
thrownewError('Taking too long!');
36-
},common.platformTimeout(1000)).unref();
37-
38-
process.on('uncaughtException',catcher);
39-
varerrors=0;
40-
functioncatcher(){
32+
leterrors=0;
33+
process.on('uncaughtException',()=>{
4134
errors++;
42-
}
35+
});
4336

44-
process.on('exit',function(){
37+
process.on('exit',()=>{
4538
assert.equal(errors,10);
46-
console.log('ok');
4739
});

0 commit comments

Comments
 (0)