summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2018-01-03 12:02:46 -0800
committerJames M Snell <jasnell@gmail.com>2018-01-05 13:27:42 -0800
commit22760f31be7f725c217f87b8a5244ff3179f54d6 (patch)
tree850323241e5528ade01a9f103a2d88f0f4632e6d /test
parent33123b97107b5e93846b01b96f535cbc39dc4d81 (diff)
downloadandroid-node-v8-22760f31be7f725c217f87b8a5244ff3179f54d6.tar.gz
android-node-v8-22760f31be7f725c217f87b8a5244ff3179f54d6.tar.bz2
android-node-v8-22760f31be7f725c217f87b8a5244ff3179f54d6.zip
http2: verify that a dependency cycle may exist
PR-URL: https://github.com/nodejs/node/pull/17968 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http2-priority-cycle-.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/parallel/test-http2-priority-cycle-.js b/test/parallel/test-http2-priority-cycle-.js
new file mode 100644
index 0000000000..af0d66d834
--- /dev/null
+++ b/test/parallel/test-http2-priority-cycle-.js
@@ -0,0 +1,69 @@
+'use strict';
+
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+const assert = require('assert');
+const http2 = require('http2');
+const Countdown = require('../common/countdown');
+
+const server = http2.createServer();
+const largeBuffer = Buffer.alloc(1e4);
+
+// Verify that a dependency cycle may exist, but that it doesn't crash anything
+
+server.on('stream', common.mustCall((stream) => {
+ stream.respond();
+ setImmediate(() => {
+ stream.end(largeBuffer);
+ });
+}, 3));
+server.on('session', common.mustCall((session) => {
+ session.on('priority', (id, parent, weight, exclusive) => {
+ assert.strictEqual(weight, 16);
+ assert.strictEqual(exclusive, false);
+ switch (id) {
+ case 1:
+ assert.strictEqual(parent, 5);
+ break;
+ case 3:
+ assert.strictEqual(parent, 1);
+ break;
+ case 5:
+ assert.strictEqual(parent, 3);
+ break;
+ default:
+ assert.fail('should not happen');
+ }
+ });
+}));
+
+server.listen(0, common.mustCall(() => {
+ const client = http2.connect(`http://localhost:${server.address().port}`);
+
+ const countdown = new Countdown(3, () => {
+ client.close();
+ server.close();
+ });
+
+ {
+ const req = client.request();
+ req.priority({ parent: 5 });
+ req.resume();
+ req.on('close', () => countdown.dec());
+ }
+
+ {
+ const req = client.request();
+ req.priority({ parent: 1 });
+ req.resume();
+ req.on('close', () => countdown.dec());
+ }
+
+ {
+ const req = client.request();
+ req.priority({ parent: 3 });
+ req.resume();
+ req.on('close', () => countdown.dec());
+ }
+}));