Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: verify that a dependency cycle may exist #17968

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions test/parallel/test-http2-priority-cycle-.js
Original file line number Diff line number Diff line change
@@ -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());
}
}));