File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 2323const  common  =  require ( '../common' ) ; 
2424const  assert  =  require ( 'assert' ) ; 
2525const  http  =  require ( 'http' ) ; 
26+ const  Countdown  =  require ( '../common/countdown' ) ; 
2627
2728let  name ; 
2829const  max  =  3 ; 
29- let  count  =  0 ; 
3030
3131const  server  =  http . Server ( common . mustCall ( ( req ,  res )  =>  { 
3232  if  ( req . url  ===  '/0' )  { 
@@ -45,21 +45,23 @@ server.listen(0, common.mustCall(() => {
4545    request ( i ) ; 
4646} ) ) ; 
4747
48+ const  countdown  =  new  Countdown ( max ,  ( )  =>  { 
49+   assert ( ! http . globalAgent . sockets . hasOwnProperty ( name ) ) ; 
50+   assert ( ! http . globalAgent . requests . hasOwnProperty ( name ) ) ; 
51+   server . close ( ) ; 
52+ } ) ; 
53+ 
4854function  request ( i )  { 
4955  const  req  =  http . get ( { 
5056    port : server . address ( ) . port , 
5157    path : `/${ i }  
5258  } ,  function ( res )  { 
5359    const  socket  =  req . socket ; 
5460    socket . on ( 'close' ,  common . mustCall ( ( )  =>  { 
55-       ++ count ; 
56-       if  ( count   <   max )  { 
61+       countdown . dec ( ) ; 
62+       if  ( countdown . remaining   >   0 )  { 
5763        assert . strictEqual ( http . globalAgent . sockets [ name ] . includes ( socket ) , 
5864                           false ) ; 
59-       }  else  { 
60-         assert ( ! http . globalAgent . sockets . hasOwnProperty ( name ) ) ; 
61-         assert ( ! http . globalAgent . requests . hasOwnProperty ( name ) ) ; 
62-         server . close ( ) ; 
6365      } 
6466    } ) ) ; 
6567    res . resume ( ) ; 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments