@@ -7,20 +7,22 @@ if (!common.hasCrypto)
7
7
const h2 = require ( 'http2' ) ;
8
8
9
9
const serverTimeout = common . platformTimeout ( 200 ) ;
10
- const callTimeout = common . platformTimeout ( 10 ) ;
10
+ const callTimeout = common . platformTimeout ( 20 ) ;
11
+ const minRuns = Math . ceil ( serverTimeout / callTimeout ) * 2 ;
12
+ const mustNotCall = common . mustNotCall ( ) ;
11
13
12
14
const server = h2 . createServer ( ) ;
13
15
server . timeout = serverTimeout ;
14
16
15
17
server . on ( 'request' , ( req , res ) => res . end ( ) ) ;
16
- server . on ( 'timeout' , common . mustNotCall ( ) ) ;
18
+ server . on ( 'timeout' , mustNotCall ) ;
17
19
18
20
server . listen ( 0 , common . mustCall ( ( ) => {
19
21
const port = server . address ( ) . port ;
20
22
21
23
const url = `http://localhost:${ port } ` ;
22
24
const client = h2 . connect ( url ) ;
23
- makeReq ( 40 ) ;
25
+ makeReq ( minRuns ) ;
24
26
25
27
function makeReq ( attempts ) {
26
28
const request = client . request ( {
@@ -29,13 +31,17 @@ server.listen(0, common.mustCall(() => {
29
31
':scheme' : 'http' ,
30
32
':authority' : `localhost:${ port } ` ,
31
33
} ) ;
34
+ request . resume ( ) ;
32
35
request . end ( ) ;
33
36
34
- if ( attempts ) {
35
- setTimeout ( ( ) => makeReq ( attempts - 1 ) , callTimeout ) ;
36
- } else {
37
- server . close ( ) ;
38
- client . destroy ( ) ;
39
- }
37
+ request . on ( 'end' , ( ) => {
38
+ if ( attempts ) {
39
+ setTimeout ( ( ) => makeReq ( attempts - 1 ) , callTimeout ) ;
40
+ } else {
41
+ server . removeListener ( 'timeout' , mustNotCall ) ;
42
+ client . destroy ( ) ;
43
+ server . close ( ) ;
44
+ }
45
+ } ) ;
40
46
}
41
47
} ) ) ;
0 commit comments