@@ -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 settings flooding causes the session to be torn down |
@@ -14,13 +16,16 @@ const kSettings = new http2util.SettingsFrame(); |
14 | 16 |
|
15 | 17 | const server = http2.createServer(); |
16 | 18 |
|
| 19 | +let interval; |
| 20 | + |
17 | 21 | server.on('stream', common.mustNotCall()); |
18 | 22 | server.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 | + |
24 | 29 | session.on('close', common.mustCall(() => { |
25 | 30 | server.close(); |
26 | 31 | })); |
@@ -30,18 +35,18 @@ server.listen(0, common.mustCall(() => { |
30 | 35 | const client = net.connect(server.address().port); |
31 | 36 |
|
32 | 37 | // 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. |
36 | 39 | // TODO(jasnell): Unfortunately, this test is inherently flaky because |
37 | 40 | // it is entirely dependent on how quickly the server is able to handle |
38 | 41 | // the inbound frames and whether those just happen to overflow nghttp2's |
39 | 42 | // outbound queue. The threshold at which the flood error occurs can vary |
40 | 43 | // from one system to another, and from one test run to another. |
41 | 44 | client.on('connect', common.mustCall(() => { |
42 | 45 | 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); |
45 | 50 | }); |
46 | 51 | })); |
47 | 52 |
|
|