From: Ben Darnell Date: Sat, 2 Mar 2013 23:46:07 +0000 (-0500) Subject: Test the IOLoop.current method and add it to TwistedIOLoop. X-Git-Tag: v3.0.0~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c85e78439b2fca1d209632b3d4f142b2af191bb;p=thirdparty%2Ftornado.git Test the IOLoop.current method and add it to TwistedIOLoop. --- diff --git a/tornado/platform/twisted.py b/tornado/platform/twisted.py index 7eb7b778d..e044701cd 100644 --- a/tornado/platform/twisted.py +++ b/tornado/platform/twisted.py @@ -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() diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index a395cde71..0ac4fcae7 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -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() diff --git a/tornado/test/twisted_test.py b/tornado/test/twisted_test.py index bcde80282..b8d9c6f78 100644 --- a/tornado/test/twisted_test.py +++ b/tornado/test/twisted_test.py @@ -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)