From ccf708cf9d3a253204b93ca71d9111567893f946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA=20=28Dell=20laptop=29?= Date: Mon, 21 Jan 2019 16:02:07 +0500 Subject: [PATCH] Test for stream .read() / .readany() / .iter_any() (#3525) (#3527) --- tests/test_streams.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_streams.py b/tests/test_streams.py index 4d4b8357ce4..e2ebda072a1 100644 --- a/tests/test_streams.py +++ b/tests/test_streams.py @@ -649,6 +649,39 @@ async def test_begin_and_end_chunk_receiving(self) -> None: assert b'' == data assert not end_of_chunk + async def test_readany_chunk_end_race(self) -> None: + stream = self._make_one() + stream.begin_http_chunk_receiving() + stream.feed_data(b'part1') + + data = await stream.readany() + assert data == b'part1' + + loop = asyncio.get_event_loop() + task = loop.create_task(stream.readany()) + + # Give a chance for task to create waiter and start waiting for it. + await asyncio.sleep(0.1) + assert stream._waiter is not None + assert not task.done() # just for sure + + # This will trigger waiter, but without feeding any data. + # stream should re-create waiter again. + stream.end_http_chunk_receiving() + + # Give a chance for task to resolve. + # If everything is OK, previous action SHOULD NOT resolve the task. + await asyncio.sleep(0.1) + assert not task.done() # The actual test + + stream.begin_http_chunk_receiving() + # This SHOULD unblock the task actually. + stream.feed_data(b'part2') + stream.end_http_chunk_receiving() + + data = await task + assert data == b'part2' + async def test_end_chunk_receiving_without_begin(self) -> None: stream = self._make_one() with pytest.raises(RuntimeError):