@@ -4,8 +4,10 @@ const common = require('../common');
4
4
if ( ! common . hasCrypto )
5
5
common . skip ( 'missing crypto' ) ;
6
6
7
+ const assert = require ( 'assert' ) ;
7
8
const http2 = require ( 'http2' ) ;
8
9
const net = require ( 'net' ) ;
10
+
9
11
const http2util = require ( '../common/http2' ) ;
10
12
11
13
// Test that ping flooding causes the session to be torn down
@@ -15,13 +17,15 @@ const kPing = new http2util.PingFrame();
15
17
16
18
const server = http2 . createServer ( ) ;
17
19
20
+ let interval ;
21
+
18
22
server . on ( 'stream' , common . mustNotCall ( ) ) ;
19
23
server . on ( 'session' , common . mustCall ( ( session ) => {
20
- session . on ( 'error' , common . expectsError ( {
21
- code : 'ERR_HTTP2_ERROR' ,
22
- message :
23
- 'Flooding was detected in this HTTP/2 session, and it must be closed'
24
- } ) ) ;
24
+ session . on ( 'error' , ( e ) => {
25
+ assert . strictEqual ( e . code , 'ERR_HTTP2_ERROR' ) ;
26
+ assert ( e . message . includes ( 'Flooding was detected' ) ) ;
27
+ clearInterval ( interval ) ;
28
+ } ) ;
25
29
session . on ( 'close' , common . mustCall ( ( ) => {
26
30
server . close ( ) ;
27
31
} ) ) ;
@@ -31,9 +35,7 @@ server.listen(0, common.mustCall(() => {
31
35
const client = net . connect ( server . address ( ) . port ) ;
32
36
33
37
// nghttp2 uses a limit of 10000 items in it's outbound queue.
34
- // If this number is exceeded, a flooding error is raised. Set
35
- // this lim higher to account for the ones that nghttp2 is
36
- // successfully able to respond to.
38
+ // If this number is exceeded, a flooding error is raised.
37
39
// TODO(jasnell): Unfortunately, this test is inherently flaky because
38
40
// it is entirely dependent on how quickly the server is able to handle
39
41
// the inbound frames and whether those just happen to overflow nghttp2's
@@ -42,8 +44,10 @@ server.listen(0, common.mustCall(() => {
42
44
client . on ( 'connect' , common . mustCall ( ( ) => {
43
45
client . write ( http2util . kClientMagic , ( ) => {
44
46
client . write ( kSettings . data , ( ) => {
45
- for ( let n = 0 ; n < 35000 ; n ++ )
46
- client . write ( kPing . data ) ;
47
+ interval = setInterval ( ( ) => {
48
+ for ( let n = 0 ; n < 10000 ; n ++ )
49
+ client . write ( kPing . data ) ;
50
+ } , 1 ) ;
47
51
} ) ;
48
52
} ) ;
49
53
} ) ) ;
0 commit comments