]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Test the IOLoop.current method and add it to TwistedIOLoop.
authorBen Darnell <ben@bendarnell.com>
Sat, 2 Mar 2013 23:46:07 +0000 (18:46 -0500)
committerBen Darnell <ben@bendarnell.com>
Sat, 2 Mar 2013 23:46:07 +0000 (18:46 -0500)
tornado/platform/twisted.py
tornado/test/ioloop_test.py
tornado/test/twisted_test.py

index 7eb7b778dcc70378e33d7aa6d21ebb568e164d06..e044701cd6ff3694b17344e6dca1c0b2587ff97c 100644 (file)
@@ -410,6 +410,7 @@ class TwistedIOLoop(tornado.ioloop.IOLoop):
             reactor = twisted.internet.reactor
         self.reactor = reactor
         self.fds = {}
+        self.reactor.callWhenRunning(self.make_current)
 
     def close(self, all_fds=False):
         self.reactor.removeAll()
index a395cde719cc7b10b1f0ab3745d9a50995dcdb68..0ac4fcae75976e4ac035667ce6db853aee225f9f 100644 (file)
@@ -155,6 +155,24 @@ class TestIOLoop(AsyncTestCase):
         self.io_loop.remove_timeout(handle)
 
 
+# Deliberately not a subclass of AsyncTestCase so the IOLoop isn't
+# automatically set as current.
+class TestIOLoopCurrent(unittest.TestCase):
+    def setUp(self):
+        self.io_loop = IOLoop()
+
+    def tearDown(self):
+        self.io_loop.close()
+
+    def test_current(self):
+        def f():
+            self.current_io_loop = IOLoop.current()
+            self.io_loop.stop()
+        self.io_loop.add_callback(f)
+        self.io_loop.start()
+        self.assertIs(self.current_io_loop, self.io_loop)
+
+
 class TestIOLoopAddCallback(AsyncTestCase):
     def setUp(self):
         super(TestIOLoopAddCallback, self).setUp()
index bcde8028256c702eb80b8c25d0aa5d928423b33a..b8d9c6f781e015f5fe0eeb5a93940547ad3be287 100644 (file)
@@ -592,6 +592,7 @@ if have_twisted:
             self.real_io_loop = SelectIOLoop()
             reactor = TornadoReactor(io_loop=self.real_io_loop)
             super(LayeredTwistedIOLoop, self).initialize(reactor=reactor)
+            self.add_callback(self.make_current)
 
         def close(self, all_fds=False):
             super(LayeredTwistedIOLoop, self).close(all_fds=all_fds)