Skip to content

Commit 996bfcc

Browse files
mithunsasidharanmaclover7
authored andcommitted
test: update test-http-timeout to use countdown
PR-URL: #17341 Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent e1054ab commit 996bfcc

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

‎test/parallel/test-http-timeout.js‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,33 @@
2323
require('../common');
2424

2525
consthttp=require('http');
26+
constCountdown=require('../common/countdown');
2627

2728
constserver=http.createServer(function(req,res){
2829
res.writeHead(200,{'Content-Type': 'text/plain'});
2930
res.end('OK');
3031
});
3132

33+
constMAX_COUNT=11;
3234
constagent=newhttp.Agent({maxSockets: 1});
35+
constcountdown=newCountdown(MAX_COUNT,()=>server.close());
3336

3437
server.listen(0,function(){
3538

36-
for(leti=0;i<11;++i){
39+
for(leti=0;i<MAX_COUNT;++i){
3740
createRequest().end();
3841
}
3942

4043
functioncallback(){}
4144

42-
letcount=0;
43-
4445
functioncreateRequest(){
4546
constreq=http.request(
4647
{port: server.address().port,path: '/',agent: agent},
4748
function(res){
4849
req.clearTimeout(callback);
4950

5051
res.on('end',function(){
51-
count++;
52-
53-
if(count===11){
54-
server.close();
55-
}
52+
countdown.dec();
5653
});
5754

5855
res.resume();

0 commit comments

Comments
(0)