Skip to content

Commit

Permalink
priority: initialize children of exclusive
Browse files Browse the repository at this point in the history
Don't forget to set `parent` property of children when inserting
exclusive node.

Fix: spdy-http2/node-spdy#244
  • Loading branch information
indutny committed Jan 25, 2016
1 parent 01084f1 commit a0602f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/spdy-transport/priority.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ PriorityNode.prototype.getPriorityRange = function getPriorityRange() {
};

PriorityNode.prototype.addChild = function addChild(child) {
child.parent = this;
utils.binaryInsert(this.children.list, child, compareChildren);
this.children.weight += child.weight;

Expand Down Expand Up @@ -128,9 +129,11 @@ PriorityTree.prototype.add = function add(options) {
if (parent === undefined)
return this.addDefault(options.id);

debug('add node=%d parent=%d',
debug('add node=%d parent=%d weight=%d exclusive=%d',
options.id,
options.parent === null ? -1 : options.parent);
options.parent === null ? -1 : options.parent,
options.weight || this.defaultWeight,
options.exclusive ? 1 : 0);

var children;
if (options.exclusive)
Expand All @@ -149,8 +152,10 @@ PriorityTree.prototype.add = function add(options) {
}

this.count++;
if (this.count > this.maxCount)
if (this.count > this.maxCount) {
debug('hit maximum remove id=%d', this.list[0].id);
this.list.shift().remove();
}

// Root node is not subject to removal
if (node.parent !== null)
Expand Down
5 changes: 5 additions & 0 deletions test/base/priority-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ describe('Stream Priority tree', function() {
assert.deepEqual([ 2, 3, 4, 5, 6 ].map(function(id) {
return tree.get(id).priority;
}), [ 0.5, 0.25, 0.125, 0.125, 0.5 ]);

// This should not throw when removing ex-child of node swapped by
// exclusive one
tree.add({ id: 7, parent: 5, exclusive: false, weight: 2 });
tree.add({ id: 8, parent: 5, exclusive: false, weight: 2 });
});

it('should use default weight', function() {
Expand Down

0 comments on commit a0602f9

Please sign in to comment.