async def consumer(self, p: BarrierState): results = [None] * 100 async for correlation_id, value in p.iterate(): results[int(correlation_id)] = (correlation_id, value) for i, (correlation_id, value) in enumerate(results): assert correlation_id == str(i) assert value == str(i)
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()] == []