@@ -4,8 +4,10 @@ const common = require('../common');
44if ( ! common . hasCrypto )
55 common . skip ( 'missing crypto' ) ;
66
7+ const assert = require ( 'assert' ) ;
78const http2 = require ( 'http2' ) ;
89const net = require ( 'net' ) ;
10+
911const http2util = require ( '../common/http2' ) ;
1012
1113// Test that settings flooding causes the session to be torn down
@@ -14,13 +16,16 @@ const kSettings = new http2util.SettingsFrame();
1416
1517const server = http2 . createServer ( ) ;
1618
19+ let interval ;
20+
1721server . on ( 'stream' , common . mustNotCall ( ) ) ;
1822server . on ( 'session' , common . mustCall ( ( session ) => {
19- session . on ( 'error' , common . expectsError ( {
20- code : 'ERR_HTTP2_ERROR' ,
21- message :
22- 'Flooding was detected in this HTTP/2 session, and it must be closed'
23- } ) ) ;
23+ session . on ( 'error' , ( e ) => {
24+ assert . strictEqual ( e . code , 'ERR_HTTP2_ERROR' ) ;
25+ assert ( e . message . includes ( 'Flooding was detected' ) ) ;
26+ clearInterval ( interval ) ;
27+ } ) ;
28+
2429 session . on ( 'close' , common . mustCall ( ( ) => {
2530 server . close ( ) ;
2631 } ) ) ;
@@ -30,18 +35,18 @@ server.listen(0, common.mustCall(() => {
3035 const client = net . connect ( server . address ( ) . port ) ;
3136
3237 // nghttp2 uses a limit of 10000 items in it's outbound queue.
33- // If this number is exceeded, a flooding error is raised. Set
34- // this lim higher to account for the ones that nghttp2 is
35- // successfully able to respond to.
38+ // If this number is exceeded, a flooding error is raised.
3639 // TODO(jasnell): Unfortunately, this test is inherently flaky because
3740 // it is entirely dependent on how quickly the server is able to handle
3841 // the inbound frames and whether those just happen to overflow nghttp2's
3942 // outbound queue. The threshold at which the flood error occurs can vary
4043 // from one system to another, and from one test run to another.
4144 client . on ( 'connect' , common . mustCall ( ( ) => {
4245 client . write ( http2util . kClientMagic , ( ) => {
43- for ( let n = 0 ; n < 35000 ; n ++ )
44- client . write ( kSettings . data ) ;
46+ interval = setInterval ( ( ) => {
47+ for ( let n = 0 ; n < 10000 ; n ++ )
48+ client . write ( kSettings . data ) ;
49+ } , 1 ) ;
4550 } ) ;
4651 } ) ) ;
4752
0 commit comments