diff options
author | James M Snell <jasnell@gmail.com> | 2017-11-21 10:52:33 -0800 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-01-02 14:56:30 -0800 |
commit | 653e894883c8009a9bf814f7ea3e931905d128e7 (patch) | |
tree | a7c713f797c756e0c0caa3a54e3edb9fe34fdfb5 /test/parallel | |
parent | d179ccac928bd45e4baca8647c3605ec36934eec (diff) | |
download | android-node-v8-653e894883c8009a9bf814f7ea3e931905d128e7.tar.gz android-node-v8-653e894883c8009a9bf814f7ea3e931905d128e7.tar.bz2 android-node-v8-653e894883c8009a9bf814f7ea3e931905d128e7.zip |
http2: strictly limit number on concurrent streams
Strictly limit the number of concurrent streams based on the
current setting of the MAX_CONCURRENT_STREAMS setting
PR-URL: https://github.com/nodejs/node/pull/16766
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Sebastiaan Deckers <sebdeckers83@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r-- | test/parallel/test-http2-too-many-streams.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/parallel/test-http2-too-many-streams.js b/test/parallel/test-http2-too-many-streams.js new file mode 100644 index 0000000000..a4a67befa0 --- /dev/null +++ b/test/parallel/test-http2-too-many-streams.js @@ -0,0 +1,60 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +const Countdown = require('../common/countdown'); +const http2 = require('http2'); +const assert = require('assert'); + +// Test that the maxConcurrentStreams setting is strictly enforced + +const server = http2.createServer({ settings: { maxConcurrentStreams: 1 } }); + +let c = 0; + +server.on('stream', common.mustCall((stream) => { + // Because we only allow one open stream at a time, + // c should never be greater than 1. + assert.strictEqual(++c, 1); + stream.respond(); + // Force some asynchronos stuff. + setImmediate(() => { + stream.end('ok'); + assert.strictEqual(--c, 0); + }); +}, 3)); + +server.listen(0, common.mustCall(() => { + const client = http2.connect(`http://localhost:${server.address().port}`); + + const countdown = new Countdown(3, common.mustCall(() => { + server.close(); + client.destroy(); + })); + + client.on('remoteSettings', common.mustCall(() => { + assert.strictEqual(client.remoteSettings.maxConcurrentStreams, 1); + + { + const req = client.request(); + req.resume(); + req.on('close', () => { + countdown.dec(); + + setImmediate(() => { + const req = client.request(); + req.resume(); + req.on('close', () => countdown.dec()); + }); + }); + } + + { + const req = client.request(); + req.resume(); + req.on('close', () => countdown.dec()); + } + })); +})); |