From: Ben Darnell Date: Fri, 30 Jul 2010 02:00:06 +0000 (-0700) Subject: Update test_ioloop to use AsyncTestCase. Rename it to ioloop_test and X-Git-Tag: v1.1.0~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66f94d2c13ce501027106df7449d48485a132820;p=thirdparty%2Ftornado.git Update test_ioloop to use AsyncTestCase. Rename it to ioloop_test and make other stylistic changes for consistency. --- diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py new file mode 100755 index 000000000..2c718a79e --- /dev/null +++ b/tornado/test/ioloop_test.py @@ -0,0 +1,28 @@ +#!/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() diff --git a/tornado/test/runtests.py b/tornado/test/runtests.py index 773c1e542..79b2cc53e 100755 --- a/tornado/test/runtests.py +++ b/tornado/test/runtests.py @@ -4,7 +4,7 @@ import unittest TEST_MODULES = [ 'tornado.httputil.doctests', 'tornado.test.stack_context_test', - 'tornado.test.test_ioloop', + 'tornado.test.ioloop_test', ] def all(): diff --git a/tornado/test/test_ioloop.py b/tornado/test/test_ioloop.py deleted file mode 100755 index 2541fa87e..000000000 --- a/tornado/test/test_ioloop.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/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()