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 22const common = require ( '../common' ) ;
33const assert = require ( 'assert' ) ;
44const http = require ( 'http' ) ;
5+ const Countdown = require ( '../common/countdown' ) ;
56
67let name ;
78const max = 3 ;
8- let count = 0 ;
99
1010const server = http . Server ( common . mustCall ( ( req , res ) => {
1111 if ( req . url === '/0' ) {
@@ -24,21 +24,23 @@ server.listen(0, common.mustCall(() => {
2424 request ( i ) ;
2525} ) ) ;
2626
27+ const countdown = new Countdown ( max , ( ) => {
28+ assert ( ! http . globalAgent . sockets . hasOwnProperty ( name ) ) ;
29+ assert ( ! http . globalAgent . requests . hasOwnProperty ( name ) ) ;
30+ server . close ( ) ;
31+ } ) ;
32+
2733function request ( i ) {
2834 const req = http . get ( {
2935 port : server . address ( ) . port ,
3036 path : `/${ i } `
3137 } , function ( res ) {
3238 const socket = req . socket ;
3339 socket . on ( 'close' , common . mustCall ( ( ) => {
34- ++ count ;
35- if ( count < max ) {
40+ countdown . dec ( ) ;
41+ if ( countdown . remaining > 0 ) {
3642 assert . strictEqual ( http . globalAgent . sockets [ name ] . includes ( socket ) ,
3743 false ) ;
38- } else {
39- assert ( ! http . globalAgent . sockets . hasOwnProperty ( name ) ) ;
40- assert ( ! http . globalAgent . requests . hasOwnProperty ( name ) ) ;
41- server . close ( ) ;
4244 }
4345 } ) ) ;
4446 res . resume ( ) ;
You can’t perform that action at this time.
0 commit comments