async def test_resume_writing_no_waiters() -> None: loop = asyncio.get_event_loop() pr = BaseProtocol(loop=loop) pr.pause_writing() assert pr._paused pr.resume_writing() assert not pr._paused
async def test_resume_writing_no_waiters() -> None: loop = asyncio.get_event_loop() pr = BaseProtocol(loop=loop) pr.pause_writing() assert pr._paused pr.resume_writing() assert not pr._paused
async def test_resume_drain_waited(loop): pr = BaseProtocol(loop=loop) tr = mock.Mock() pr.connection_made(tr) pr.pause_writing() t = loop.create_task(pr._drain_helper()) await asyncio.sleep(0) assert pr._drain_waiter is not None pr.resume_writing() assert (await t) is None assert pr._drain_waiter is None
async def test_parallel_drain_race_condition() -> None: loop = asyncio.get_event_loop() pr = BaseProtocol(loop=loop) tr = mock.Mock() pr.connection_made(tr) pr.pause_writing() ts = [loop.create_task(pr._drain_helper()) for _ in range(5)] assert not (await asyncio.wait( ts, timeout=0.5))[0], "All draining tasks must be pending" assert pr._drain_waiter is not None pr.resume_writing() await asyncio.gather(*ts) assert pr._drain_waiter is None
async def test_resume_drain_cancelled(loop): pr = BaseProtocol(loop=loop) tr = mock.Mock() pr.connection_made(tr) pr.pause_writing() fut = loop.create_future() async def wait(): fut.set_result(None) await pr._drain_helper() t = loop.create_task(wait()) await fut t.cancel() assert pr._drain_waiter is not None pr.resume_writing() with suppress(asyncio.CancelledError): await t assert pr._drain_waiter is None
def test_resume_writing_no_waiters(loop): pr = BaseProtocol(loop=loop) pr.pause_writing() assert pr._paused pr.resume_writing() assert not pr._paused