Skip to content

Commit

Permalink
Merge pull request #39 from python-hyper/issue-38
Browse files Browse the repository at this point in the history
Allow exclusive dependency on stream 0 (as None).
  • Loading branch information
Lukasa committed Nov 11, 2016
2 parents 8f6c0c3 + e21dbbd commit c2bc33c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

dev
---

**Bugfixes**

- Allow ``insert_stream`` to be called with ``exclusive=True`` but no explicit
``depends_on`` value.

1.2.1 (2016-10-26)
------------------

Expand Down
7 changes: 3 additions & 4 deletions src/priority/priority.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,15 @@ def insert_stream(self,

stream = Stream(stream_id, weight)

if not depends_on:
depends_on = 0

if exclusive:
assert depends_on is not None
parent_stream = self._get_or_insert_parent(depends_on)
self._exclusive_insert(parent_stream, stream)
self._streams[stream_id] = stream
return

if not depends_on:
depends_on = 0

parent = self._get_or_insert_parent(depends_on)
parent.add_child(stream)
self._streams[stream_id] = stream
Expand Down
20 changes: 20 additions & 0 deletions test/test_priority.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ def test_priority_tree_raises_deadlock_error_if_all_blocked(self):
(7, 1, True, 16, [1], [7, 3, 7, 3, 7, 3, 7, 3, 7]),
(7, 1, True, 16, [1, 7], [5, 3, 11, 3, 5, 3, 11, 3, 5]),
(1, 0, False, 32, [], [1, 3, 7, 1, 7, 1, 3, 7, 1]),
(1, 0, True, 32, [], [1, 1, 1, 1, 1, 1, 1, 1, 1]),
(1, 0, True, 32, [1], [3, 5, 7, 7, 3, 5, 7, 7, 3]),
(1, None, True, 32, [], [1, 1, 1, 1, 1, 1, 1, 1, 1]),
(1, None, True, 32, [1], [3, 5, 7, 7, 3, 5, 7, 7, 3]),
]
)
def test_can_reprioritize_a_stream(self,
Expand Down Expand Up @@ -371,6 +375,22 @@ def test_priority_refuses_to_allow_too_many_streams_in_tree(self, count):
with pytest.raises(priority.TooManyStreamsError):
p.insert_stream(x + 1)

@pytest.mark.parametrize('depends_on', [0, None])
def test_can_insert_stream_with_exclusive_dependency_on_0(self,
depends_on):
"""
It is acceptable to insert a stream with an exclusive dependency on
stream 0, both explicitly and implicitly.
"""
p = priority.PriorityTree()
p.insert_stream(stream_id=1)
p.insert_stream(stream_id=3)

p.insert_stream(stream_id=5, depends_on=depends_on, exclusive=True)

next_ten_ids = [next(p) for _ in range(0, 10)]
assert next_ten_ids == [5] * 10


class TestPriorityTreeOutput(object):
"""
Expand Down

0 comments on commit c2bc33c

Please sign in to comment.