Skip to content

Commit 4652bf2

Browse files
authored
Rewrite asyncio test to be more meaningful (python#4363)
1 parent 9f914a0 commit 4652bf2

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Lib/test/test_asyncio/test_base_events.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -530,20 +530,25 @@ def test_run_until_complete_loop(self):
530530
other_loop.run_until_complete, task)
531531

532532
def test_run_until_complete_loop_orphan_future_close_loop(self):
533-
async def foo(sec=0):
534-
await asyncio.sleep(sec)
533+
class ShowStopper(BaseException):
534+
pass
535535

536-
self.loop.close()
537-
loop = asyncio.new_event_loop()
538-
asyncio.set_event_loop(loop)
536+
async def foo(delay):
537+
await asyncio.sleep(delay, loop=self.loop)
538+
539+
def throw():
540+
raise ShowStopper
541+
542+
self.loop._process_events = mock.Mock()
543+
self.loop.call_soon(throw)
539544
try:
540-
with mock.patch('asyncio.base_events.BaseEventLoop.run_forever',
541-
side_effect=Exception):
542-
loop.run_until_complete(foo())
543-
except:
545+
self.loop.run_until_complete(foo(0.1))
546+
except ShowStopper:
544547
pass
545-
loop.run_until_complete(foo(0.1))
546-
loop.close()
548+
549+
# This call fails if run_until_complete does not clean up
550+
# done-callback for the previous future.
551+
self.loop.run_until_complete(foo(0.2))
547552

548553
def test_subprocess_exec_invalid_args(self):
549554
args = [sys.executable, '-c', 'pass']

0 commit comments

Comments
 (0)