summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2017-11-10 20:34:17 (GMT)
committerGitHub <noreply@github.com>2017-11-10 20:34:17 (GMT)
commit4652bf2acc0d1ddabd224efabbfee0c3125da18b (patch)
tree853e5c9c0898ff85a44579ca7f1f3e1fb8807ccd /Lib/test
parent9f914a01affc55abe799afc521ce71612bb495a5 (diff)
downloadcpython-4652bf2acc0d1ddabd224efabbfee0c3125da18b.zip
cpython-4652bf2acc0d1ddabd224efabbfee0c3125da18b.tar.gz
cpython-4652bf2acc0d1ddabd224efabbfee0c3125da18b.tar.bz2
Rewrite asyncio test to be more meaningful (#4363)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_base_events.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 6fdb593..a25069e 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -530,20 +530,25 @@ class BaseEventLoopTests(test_utils.TestCase):
other_loop.run_until_complete, task)
def test_run_until_complete_loop_orphan_future_close_loop(self):
- async def foo(sec=0):
- await asyncio.sleep(sec)
+ class ShowStopper(BaseException):
+ pass
- self.loop.close()
- loop = asyncio.new_event_loop()
- asyncio.set_event_loop(loop)
+ async def foo(delay):
+ await asyncio.sleep(delay, loop=self.loop)
+
+ def throw():
+ raise ShowStopper
+
+ self.loop._process_events = mock.Mock()
+ self.loop.call_soon(throw)
try:
- with mock.patch('asyncio.base_events.BaseEventLoop.run_forever',
- side_effect=Exception):
- loop.run_until_complete(foo())
- except:
+ self.loop.run_until_complete(foo(0.1))
+ except ShowStopper:
pass
- loop.run_until_complete(foo(0.1))
- loop.close()
+
+ # This call fails if run_until_complete does not clean up
+ # done-callback for the previous future.
+ self.loop.run_until_complete(foo(0.2))
def test_subprocess_exec_invalid_args(self):
args = [sys.executable, '-c', 'pass']