Permalink
Browse files

Factor port-selection logic out of AsyncHTTPTestCase so it can be used

from lower-level tests
  • Loading branch information...
1 parent 7a7e241 commit b02a31b668af71160c84b1c95a22e1035d9c218a @bdarnell bdarnell committed Sep 27, 2010
Showing with 10 additions and 6 deletions.
  1. +10 −6 tornado/testing.py
View
@@ -31,6 +31,14 @@
import traceback
import unittest
+_next_port = 10000
+def get_unused_port():
+ """Returns a (hopefully) unused port number."""
+ global _next_port
+ port = _next_port
+ _next_port = _next_port + 1
+ return port
+
class AsyncTestCase(unittest.TestCase):
"""TestCase subclass for testing IOLoop-based asynchronous code.
@@ -193,8 +201,6 @@ def test_homepage(self):
response = self.wait()
# test contents of response
'''
- __next_port = 10000
-
def setUp(self):
super(AsyncHTTPTestCase, self).setUp()
self.__port = None
@@ -222,10 +228,8 @@ def get_http_port(self):
A new port is chosen for each test.
"""
- if self.__port is not None:
- return self.__port
- self.__port = AsyncHTTPTestCase.__next_port
- AsyncHTTPTestCase.__next_port = self.__port + 1
+ if self.__port is None:
+ self.__port = get_unused_port()
return self.__port
def get_url(self, path):

0 comments on commit b02a31b

Please sign in to comment.