async def test_parallel_iterate(self): p = BarrierState(reply_to='rt') assert not p.pending assert p.size == 0 done, pending = await asyncio.wait( [ self.adder(p), self.fulfiller(p), self.finalizer(p, 1.0), self.consumer(p), ], timeout=5.0, ) if pending: raise Exception(f'Test did not return in 5s:\n' f' DONE_TASKS={done}\n' f' PENDING_TASKS={pending}\n' f' size={p.size}\n' f' total={p.total}\n' f' fulfilled={p.fulfilled}\n' f' pending={len(p.pending)}\n' f' done={p.done()}' f' result={p.result() if p.done() else None}')
async def test_sync_join(self): p = BarrierState(reply_to='rt') assert not p.pending assert p.size == 0 await self.adder(p) await self.fulfiller(p) await self.finalizer(p, 0.0) await self.joiner(p) assert p.get_nowait()
async def test_sync_iterate(self): p = BarrierState(reply_to='rt') assert not p.pending assert p.size == 0 await self.adder(p) await self.finalizer(p, 0.0) await self.fulfiller(p) assert p.done() await self.consumer(p)
async def test_parallel_join(self): p = BarrierState(reply_to='rt') assert not p.pending assert p.size == 0 await asyncio.gather( self.adder(p), self.fulfiller(p), self.finalizer(p, 1.0), self.joiner(p), )
async def test_iterate__completion(self): p = BarrierState(reply_to='rt') p.done = Mock(name='done') p.done.return_value = False p._results.put_nowait(None) p._results.get = AsyncMock(name='get') def se(): p.done.return_value = True return None p._results.get.coro.side_effect = se assert [x async for x in p.iterate()] == []
async def test_get_nowait__exhaust_sentinels(self): p = BarrierState(reply_to='rt') for _ in range(20): p._results.put_nowait(None) with pytest.raises(asyncio.QueueEmpty): p.get_nowait()