vomebook commited on
Commit ·
775dc9e
1
Parent(s): 2390b8f
Bound closed proxy subscription test before cancellation
Browse files
tests/proxy/test_proxy_streams_contract.py
CHANGED
|
@@ -157,7 +157,20 @@ class ProxyOwnershipTests(unittest.IsolatedAsyncioTestCase):
|
|
| 157 |
subscriber = RangeSubscription(flight)
|
| 158 |
subscriber.closed = True
|
| 159 |
flight.chunks.append(b'must not leak')
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
self.assertTrue(flight.started.is_set())
|
| 162 |
self.assertIsNone(subscriber.flight)
|
| 163 |
|
|
|
|
| 157 |
subscriber = RangeSubscription(flight)
|
| 158 |
subscriber.closed = True
|
| 159 |
flight.chunks.append(b'must not leak')
|
| 160 |
+
|
| 161 |
+
async def collect():
|
| 162 |
+
return [chunk async for chunk in subscriber.stream()]
|
| 163 |
+
|
| 164 |
+
task = asyncio.create_task(collect())
|
| 165 |
+
try:
|
| 166 |
+
done, _ = await asyncio.wait({task}, timeout=1)
|
| 167 |
+
# Check before cancellation: the stream may suppress CancelledError.
|
| 168 |
+
self.assertIn(task, done, 'closed subscriber stream did not finish within 1 second')
|
| 169 |
+
self.assertEqual(task.result(), [])
|
| 170 |
+
finally:
|
| 171 |
+
if not task.done():
|
| 172 |
+
task.cancel()
|
| 173 |
+
await asyncio.gather(task, return_exceptions=True)
|
| 174 |
self.assertTrue(flight.started.is_set())
|
| 175 |
self.assertIsNone(subscriber.flight)
|
| 176 |
|