Skip to content

Commit

Permalink
http2: verify that a dependency cycle may exist
Browse files Browse the repository at this point in the history
PR-URL: nodejs#17968
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
jasnell authored and MylesBorins committed Jan 9, 2018
1 parent adbc38a commit 51dc318
Showing 1 changed file with 69 additions and 0 deletions.
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());
}
}));

0 comments on commit 51dc318

Please sign in to comment.