fix async generator junction tests
This commit is contained in:
parent
418def56ac
commit
4630fd38aa
1 changed files with 9 additions and 9 deletions
|
@ -41,16 +41,16 @@ class TestAsyncGeneratorJunction(AsyncioTestCase):
|
||||||
|
|
||||||
async def test_yield_order(self):
|
async def test_yield_order(self):
|
||||||
expected_order = [1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 2, 2, 2]
|
expected_order = [1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 2, 2, 2]
|
||||||
fast_gen = MockAsyncGen(self.loop, 1, 0.1)
|
fast_gen = MockAsyncGen(self.loop, 1, 0.2)
|
||||||
slow_gen = MockAsyncGen(self.loop, 2, 0.2)
|
slow_gen = MockAsyncGen(self.loop, 2, 0.4)
|
||||||
await self._test_junction(expected_order, fast_gen, slow_gen)
|
await self._test_junction(expected_order, fast_gen, slow_gen)
|
||||||
self.assertEqual(fast_gen.called_close, True)
|
self.assertEqual(fast_gen.called_close, True)
|
||||||
self.assertEqual(slow_gen.called_close, True)
|
self.assertEqual(slow_gen.called_close, True)
|
||||||
|
|
||||||
async def test_one_stopped_first(self):
|
async def test_one_stopped_first(self):
|
||||||
expected_order = [1, 2, 1, 1, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2]
|
expected_order = [1, 2, 1, 1, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2]
|
||||||
fast_gen = MockAsyncGen(self.loop, 1, 0.101, 5)
|
fast_gen = MockAsyncGen(self.loop, 1, 0.2, 5)
|
||||||
slow_gen = MockAsyncGen(self.loop, 2, 0.201)
|
slow_gen = MockAsyncGen(self.loop, 2, 0.4)
|
||||||
await self._test_junction(expected_order, fast_gen, slow_gen)
|
await self._test_junction(expected_order, fast_gen, slow_gen)
|
||||||
self.assertEqual(fast_gen.called_close, True)
|
self.assertEqual(fast_gen.called_close, True)
|
||||||
self.assertEqual(slow_gen.called_close, True)
|
self.assertEqual(slow_gen.called_close, True)
|
||||||
|
@ -62,16 +62,16 @@ class TestAsyncGeneratorJunction(AsyncioTestCase):
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
if i == 5:
|
if i == 5:
|
||||||
return
|
return
|
||||||
await asyncio.sleep(0.101)
|
await asyncio.sleep(0.2)
|
||||||
yield 1
|
yield 1
|
||||||
|
|
||||||
slow_gen = MockAsyncGen(self.loop, 2, 0.201)
|
slow_gen = MockAsyncGen(self.loop, 2, 0.4)
|
||||||
await self._test_junction(expected_order, fast_gen(), slow_gen)
|
await self._test_junction(expected_order, fast_gen(), slow_gen)
|
||||||
self.assertEqual(slow_gen.called_close, True)
|
self.assertEqual(slow_gen.called_close, True)
|
||||||
|
|
||||||
async def test_stop_when_encapsulating_task_cancelled(self):
|
async def test_stop_when_encapsulating_task_cancelled(self):
|
||||||
fast_gen = MockAsyncGen(self.loop, 1, 0.1)
|
fast_gen = MockAsyncGen(self.loop, 1, 0.2)
|
||||||
slow_gen = MockAsyncGen(self.loop, 2, 0.2)
|
slow_gen = MockAsyncGen(self.loop, 2, 0.4)
|
||||||
|
|
||||||
async def _task():
|
async def _task():
|
||||||
async with AsyncGeneratorJunction(self.loop) as junction:
|
async with AsyncGeneratorJunction(self.loop) as junction:
|
||||||
|
@ -81,7 +81,7 @@ class TestAsyncGeneratorJunction(AsyncioTestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
task = self.loop.create_task(_task())
|
task = self.loop.create_task(_task())
|
||||||
self.loop.call_later(0.5, task.cancel)
|
self.loop.call_later(1.0, task.cancel)
|
||||||
with self.assertRaises(asyncio.CancelledError):
|
with self.assertRaises(asyncio.CancelledError):
|
||||||
await task
|
await task
|
||||||
self.assertEqual(fast_gen.called_close, True)
|
self.assertEqual(fast_gen.called_close, True)
|
||||||
|
|
Loading…
Add table
Reference in a new issue