|
44 | 44 | ) |
45 | 45 |
|
46 | 46 |
|
47 | | - |
48 | 47 | def readme_tree(): |
49 | 48 | """ |
50 | 49 | Provide a tree configured as the one in the readme. |
@@ -113,6 +112,38 @@ def test_stream_repr(self): |
113 | 112 | s = priority.Stream(stream_id=80, weight=16) |
114 | 113 | assert repr(s) == "Stream<id=80, weight=16>" |
115 | 114 |
|
| 115 | + @given(STREAMS_AND_WEIGHTS) |
| 116 | + def test_streams_are_well_ordered(self, streams_and_weights): |
| 117 | + """ |
| 118 | + Streams are ordered by their stream ID. |
| 119 | + """ |
| 120 | + stream_list = [ |
| 121 | + priority.Stream(stream_id=s, weight=w) |
| 122 | + for s, w in streams_and_weights |
| 123 | + ] |
| 124 | + stream_list = sorted(stream_list) |
| 125 | + streams_by_id = [stream.stream_id for stream in stream_list] |
| 126 | + assert sorted(streams_by_id) == streams_by_id |
| 127 | + |
| 128 | + @given( |
| 129 | + integers(min_value=1, max_value=2**24), |
| 130 | + integers(min_value=1, max_value=2**24) |
| 131 | + ) |
| 132 | + def test_stream_ordering(self, a, b): |
| 133 | + """ |
| 134 | + Two streams are well ordered based on their stream ID. |
| 135 | + """ |
| 136 | + s1 = priority.Stream(stream_id=a, weight=16) |
| 137 | + s2 = priority.Stream(stream_id=b, weight=32) |
| 138 | + |
| 139 | + assert (s1 < s2) == (a < b) |
| 140 | + assert (s1 <= s2) == (a <= b) |
| 141 | + assert (s1 > s2) == (a > b) |
| 142 | + assert (s1 >= s2) == (a >= b) |
| 143 | + assert (s1 == s2) == (a == b) |
| 144 | + assert (s1 != s2) == (a != b) |
| 145 | + |
| 146 | + |
116 | 147 |
|
117 | 148 | class TestPriorityTreeManual(object): |
118 | 149 | """ |
@@ -161,6 +192,24 @@ def test_priority_tree_blocking_is_isomorphic(self, |
161 | 192 | result = [next(tree) for _ in range(len(expected))] |
162 | 193 | assert expected == result |
163 | 194 |
|
| 195 | + @given(BLOCKED_AND_ACTIVE) |
| 196 | + def test_removing_items_behaves_similarly_to_blocking(self, |
| 197 | + blocked_expected): |
| 198 | + """ |
| 199 | + From the perspective of iterating over items, removing streams should |
| 200 | + have the same effect as blocking them, except that the ordering |
| 201 | + changes. Because the ordering is not important, don't test for it. |
| 202 | + """ |
| 203 | + tree = readme_tree() |
| 204 | + blocked = blocked_expected[0] |
| 205 | + expected = set(blocked_expected[1]) |
| 206 | + |
| 207 | + for stream_id in blocked: |
| 208 | + tree.remove_stream(stream_id) |
| 209 | + |
| 210 | + result = set(next(tree) for _ in range(len(expected))) |
| 211 | + assert expected == result |
| 212 | + |
164 | 213 | def test_priority_tree_raises_deadlock_error_if_all_blocked(self): |
165 | 214 | """ |
166 | 215 | Assuming all streams are blocked and none can progress, asking for the |
|
0 commit comments