]> granicus.if.org Git - python/commitdiff
[asyncio] bpo-30423: add regression test for orphan future causes "RuntimeError:...
authorjimmylai <albert_chs@yahoo.com.tw>
Wed, 1 Nov 2017 13:54:45 +0000 (06:54 -0700)
committerAndrew Svetlov <andrew.svetlov@gmail.com>
Wed, 1 Nov 2017 13:54:45 +0000 (15:54 +0200)
* call remove_done_callback in finally section

* [asyncio] bpo-30423 bug: add regression test for orphan future causes "RuntimeError: Event loop stopped before Future completed."

Lib/test/test_asyncio/test_base_events.py

index a0ce9fa55e06afca9c67db4a62dd1c43b35e2131..6fdb593da6ed048fa324c48ee12899b3be699e22 100644 (file)
@@ -529,6 +529,22 @@ class BaseEventLoopTests(test_utils.TestCase):
         self.assertRaises(ValueError,
             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)
+
+        self.loop.close()
+        loop = asyncio.new_event_loop()
+        asyncio.set_event_loop(loop)
+        try:
+            with mock.patch('asyncio.base_events.BaseEventLoop.run_forever', 
+                            side_effect=Exception):
+                loop.run_until_complete(foo())
+        except:
+            pass
+        loop.run_until_complete(foo(0.1))
+        loop.close()
+
     def test_subprocess_exec_invalid_args(self):
         args = [sys.executable, '-c', 'pass']