]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Minor cleanups for import deadlock test:
authorBen Darnell <ben@bendarnell.com>
Mon, 23 Dec 2013 21:10:42 +0000 (16:10 -0500)
committerBen Darnell <ben@bendarnell.com>
Mon, 23 Dec 2013 21:15:39 +0000 (16:15 -0500)
* Avoid _test.py suffix for file that doesn't contain test cases.
* Resolve localhost instead of tornadoweb.org to avoid network dependency.
* Tighten timeout and add an alarm so failed tests don't leave orphaned
  child processes.
* Avoid busy loop while waiting for child to exit.

tornado/test/netutil_test.py
tornado/test/resolve_test_helper.py [moved from tornado/test/resolve_test.py with 82% similarity]

index 2501eab503721fd619140be3d786492c428f3d7c..d99e524c265d7b6919d9e513f34861eec2548ce9 100644 (file)
@@ -1,5 +1,6 @@
 from __future__ import absolute_import, division, print_function, with_statement
 
+import signal
 import socket
 from subprocess import Popen
 import sys
@@ -63,21 +64,24 @@ class ThreadedResolverTest(AsyncTestCase, _ResolverTestMixin):
 @unittest.skipIf(futures is None, "futures module not present")
 class ThreadedResolverImportTest(unittest.TestCase):
     def test_import(self):
+        TIMEOUT = 5
+
         # Test for a deadlock when importing a module that runs the
         # ThreadedResolver at import-time. See resolve_test.py for
         # full explanation.
         command = [
             sys.executable,
             '-c',
-            'import tornado.test.resolve_test']
+            'import tornado.test.resolve_test_helper']
 
         start = time.time()
-        popen = Popen(command)
-        while time.time() - start < 20:
+        popen = Popen(command, preexec_fn=lambda: signal.alarm(TIMEOUT))
+        while time.time() - start < TIMEOUT:
             return_code = popen.poll()
             if return_code is not None:
                 self.assertEqual(0, return_code)
                 return  # Success.
+            time.sleep(0.05)
 
         self.fail("import timed out")
 
similarity index 82%
rename from tornado/test/resolve_test.py
rename to tornado/test/resolve_test_helper.py
index 5df8061b75145df7297dc4dad77b7792353fc865..b4032fc4a4e0e093efe1e96a43dad4fa8e0ac654 100644 (file)
@@ -8,4 +8,4 @@ from tornado.util import u
 # this deadlock.
 
 resolver = ThreadedResolver()
-IOLoop.current().run_sync(lambda: resolver.resolve(u('tornadoweb.org'), 80))
+IOLoop.current().run_sync(lambda: resolver.resolve(u('localhost'), 80))