Skip to content

Commit a85518e

Browse files
jasnellMylesBorins
authored andcommitted
http2: verify that a dependency cycle may exist
Backport-PR-URL: #18050 Backport-PR-URL: #20456 PR-URL: #17968 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 9c85ada commit a85518e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
const assert = require('assert');
7+
const http2 = require('http2');
8+
const Countdown = require('../common/countdown');
9+
10+
const server = http2.createServer();
11+
const largeBuffer = Buffer.alloc(1e4);
12+
13+
// Verify that a dependency cycle may exist, but that it doesn't crash anything
14+
15+
server.on('stream', common.mustCall((stream) => {
16+
stream.respond();
17+
setImmediate(() => {
18+
stream.end(largeBuffer);
19+
});
20+
}, 3));
21+
server.on('session', common.mustCall((session) => {
22+
session.on('priority', (id, parent, weight, exclusive) => {
23+
assert.strictEqual(weight, 16);
24+
assert.strictEqual(exclusive, false);
25+
switch (id) {
26+
case 1:
27+
assert.strictEqual(parent, 5);
28+
break;
29+
case 3:
30+
assert.strictEqual(parent, 1);
31+
break;
32+
case 5:
33+
assert.strictEqual(parent, 3);
34+
break;
35+
default:
36+
assert.fail('should not happen');
37+
}
38+
});
39+
}));
40+
41+
server.listen(0, common.mustCall(() => {
42+
const client = http2.connect(`http://localhost:${server.address().port}`);
43+
44+
const countdown = new Countdown(3, () => {
45+
client.close();
46+
server.close();
47+
});
48+
49+
{
50+
const req = client.request();
51+
req.priority({ parent: 5 });
52+
req.resume();
53+
req.on('close', () => countdown.dec());
54+
}
55+
56+
{
57+
const req = client.request();
58+
req.priority({ parent: 1 });
59+
req.resume();
60+
req.on('close', () => countdown.dec());
61+
}
62+
63+
{
64+
const req = client.request();
65+
req.priority({ parent: 3 });
66+
req.resume();
67+
req.on('close', () => countdown.dec());
68+
}
69+
}));

0 commit comments

Comments
 (0)