make other stylistic changes for consistency.
--- /dev/null
+#!/usr/bin/env python
+
+import unittest
+import time
+
+from tornado import ioloop
+from tornado.testing import AsyncTestCase, LogTrapTestCase
+
+class TestIOLoop(AsyncTestCase, LogTrapTestCase):
+ def test_add_callback_wakeup(self):
+ # Make sure that add_callback from inside a running IOLoop
+ # wakes up the IOLoop immediately instead of waiting for a timeout.
+ def callback():
+ self.called = True
+ self.stop()
+
+ def schedule_callback():
+ self.called = False
+ self.io_loop.add_callback(callback)
+ # Store away the time so we can check if we woke up immediately
+ self.start_time = time.time()
+ self.io_loop.add_timeout(time.time(), schedule_callback)
+ self.wait()
+ self.assertAlmostEqual(time.time(), self.start_time, places=2)
+ self.assertTrue(self.called)
+
+if __name__ == "__main__":
+ unittest.main()
TEST_MODULES = [
'tornado.httputil.doctests',
'tornado.test.stack_context_test',
- 'tornado.test.test_ioloop',
+ 'tornado.test.ioloop_test',
]
def all():
+++ /dev/null
-#!/usr/bin/env python
-
-import unittest
-import time
-
-from tornado import ioloop
-
-
-class TestIOLoop(unittest.TestCase):
- def setUp(self):
- self.loop = ioloop.IOLoop()
-
- def tearDown(self):
- pass
-
- def _callback(self):
- self.called = True
- self.loop.stop()
-
- def _schedule_callback(self):
- self.loop.add_callback(self._callback)
- # Scroll away the time so we can check if we woke up immediately
- self._start_time = time.time()
- self.called = False
-
- def test_add_callback(self):
- self.loop.add_timeout(time.time(), self._schedule_callback)
- self.loop.start() # Set some long poll timeout so we can check wakeup
- self.assertAlmostEqual(time.time(), self._start_time, places=2)
- self.assertTrue(self.called)
-
-
-if __name__ == "__main__":
- import logging
-
- logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(msecs)03d %(levelname)-8s %(name)-8s %(message)s', datefmt='%H:%M:%S')
-
- unittest.main()