Skip to content

Commit c2bc33c

Browse files
authored
Merge pull request python-hyper#39 from python-hyper/issue-38
Allow exclusive dependency on stream 0 (as None).
2 parents 8f6c0c3 + e21dbbd commit c2bc33c

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

HISTORY.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
dev
5+
---
6+
7+
**Bugfixes**
8+
9+
- Allow ``insert_stream`` to be called with ``exclusive=True`` but no explicit
10+
``depends_on`` value.
11+
412
1.2.1 (2016-10-26)
513
------------------
614

src/priority/priority.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,15 @@ def insert_stream(self,
286286

287287
stream = Stream(stream_id, weight)
288288

289+
if not depends_on:
290+
depends_on = 0
291+
289292
if exclusive:
290-
assert depends_on is not None
291293
parent_stream = self._get_or_insert_parent(depends_on)
292294
self._exclusive_insert(parent_stream, stream)
293295
self._streams[stream_id] = stream
294296
return
295297

296-
if not depends_on:
297-
depends_on = 0
298-
299298
parent = self._get_or_insert_parent(depends_on)
300299
parent.add_child(stream)
301300
self._streams[stream_id] = stream

test/test_priority.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ def test_priority_tree_raises_deadlock_error_if_all_blocked(self):
235235
(7, 1, True, 16, [1], [7, 3, 7, 3, 7, 3, 7, 3, 7]),
236236
(7, 1, True, 16, [1, 7], [5, 3, 11, 3, 5, 3, 11, 3, 5]),
237237
(1, 0, False, 32, [], [1, 3, 7, 1, 7, 1, 3, 7, 1]),
238+
(1, 0, True, 32, [], [1, 1, 1, 1, 1, 1, 1, 1, 1]),
239+
(1, 0, True, 32, [1], [3, 5, 7, 7, 3, 5, 7, 7, 3]),
240+
(1, None, True, 32, [], [1, 1, 1, 1, 1, 1, 1, 1, 1]),
241+
(1, None, True, 32, [1], [3, 5, 7, 7, 3, 5, 7, 7, 3]),
238242
]
239243
)
240244
def test_can_reprioritize_a_stream(self,
@@ -371,6 +375,22 @@ def test_priority_refuses_to_allow_too_many_streams_in_tree(self, count):
371375
with pytest.raises(priority.TooManyStreamsError):
372376
p.insert_stream(x + 1)
373377

378+
@pytest.mark.parametrize('depends_on', [0, None])
379+
def test_can_insert_stream_with_exclusive_dependency_on_0(self,
380+
depends_on):
381+
"""
382+
It is acceptable to insert a stream with an exclusive dependency on
383+
stream 0, both explicitly and implicitly.
384+
"""
385+
p = priority.PriorityTree()
386+
p.insert_stream(stream_id=1)
387+
p.insert_stream(stream_id=3)
388+
389+
p.insert_stream(stream_id=5, depends_on=depends_on, exclusive=True)
390+
391+
next_ten_ids = [next(p) for _ in range(0, 10)]
392+
assert next_ten_ids == [5] * 10
393+
374394

375395
class TestPriorityTreeOutput(object):
376396
"""

0 commit comments

Comments
 (0)