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 2
2
const common = require ( '../common' ) ;
3
3
const assert = require ( 'assert' ) ;
4
4
const http = require ( 'http' ) ;
5
+ const Countdown = require ( '../common/countdown' ) ;
5
6
6
7
let name ;
7
8
const max = 3 ;
8
- let count = 0 ;
9
9
10
10
const server = http . Server ( common . mustCall ( ( req , res ) => {
11
11
if ( req . url === '/0' ) {
@@ -24,21 +24,23 @@ server.listen(0, common.mustCall(() => {
24
24
request ( i ) ;
25
25
} ) ) ;
26
26
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
+
27
33
function request ( i ) {
28
34
const req = http . get ( {
29
35
port : server . address ( ) . port ,
30
36
path : `/${ i } `
31
37
} , function ( res ) {
32
38
const socket = req . socket ;
33
39
socket . on ( 'close' , common . mustCall ( ( ) => {
34
- ++ count ;
35
- if ( count < max ) {
40
+ countdown . dec ( ) ;
41
+ if ( countdown . remaining > 0 ) {
36
42
assert . strictEqual ( http . globalAgent . sockets [ name ] . includes ( socket ) ,
37
43
false ) ;
38
- } else {
39
- assert ( ! http . globalAgent . sockets . hasOwnProperty ( name ) ) ;
40
- assert ( ! http . globalAgent . requests . hasOwnProperty ( name ) ) ;
41
- server . close ( ) ;
42
44
}
43
45
} ) ) ;
44
46
res . resume ( ) ;
You can’t perform that action at this time.
0 commit comments