summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-03-21 09:00:52 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-03-21 09:00:52 (GMT)
commit93569c2b3d48b36df80635dbe3c02e3d5baa00d7 (patch)
tree0b00d71b628b2fbd5e99caafb56e5a05b396614c /Lib/test
parent4137465bf546964736e45bed16a15d05000b26e8 (diff)
downloadcpython-93569c2b3d48b36df80635dbe3c02e3d5baa00d7.zip
cpython-93569c2b3d48b36df80635dbe3c02e3d5baa00d7.tar.gz
cpython-93569c2b3d48b36df80635dbe3c02e3d5baa00d7.tar.bz2
asyncio: Ensure call_soon(), call_later() and call_at() are invoked on current
loop in debug mode. Raise a RuntimeError if the event loop of the current thread is different. The check should help to debug thread-safetly issue. Patch written by David Foster.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_base_events.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 340ca67..544bd3d 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -136,6 +136,29 @@ class BaseEventLoopTests(unittest.TestCase):
# are really slow
self.assertLessEqual(dt, 0.9, dt)
+ def test_assert_is_current_event_loop(self):
+ def cb():
+ pass
+
+ other_loop = base_events.BaseEventLoop()
+ other_loop._selector = unittest.mock.Mock()
+ asyncio.set_event_loop(other_loop)
+
+ # raise RuntimeError if the event loop is different in debug mode
+ self.loop.set_debug(True)
+ with self.assertRaises(RuntimeError):
+ self.loop.call_soon(cb)
+ with self.assertRaises(RuntimeError):
+ self.loop.call_later(60, cb)
+ with self.assertRaises(RuntimeError):
+ self.loop.call_at(self.loop.time() + 60, cb)
+
+ # check disabled if debug mode is disabled
+ self.loop.set_debug(False)
+ self.loop.call_soon(cb)
+ self.loop.call_later(60, cb)
+ self.loop.call_at(self.loop.time() + 60, cb)
+
def test_run_once_in_executor_handle(self):
def cb():
pass