Refactor TCP test suite.

This commit is contained in:
Aldo Cortesi 2012-07-05 09:37:43 +12:00
parent 96af5c16a0
commit 20cc1b6aa4
2 changed files with 10 additions and 22 deletions

View File

@ -209,7 +209,7 @@ class TCPServer:
request.close() request.close()
# Why a blanket except here? In some circumstances, a thread can # Why a blanket except here? In some circumstances, a thread can
# persist until the interpreter exits. When this happens, all modules # persist until the interpreter exits. When this happens, all modules
# and builtins are set to None, and things balls up indeterminate # and builtins are set to None, and things balls up in indeterminate
# ways. # ways.
except: except:
pass pass

View File

@ -17,7 +17,10 @@ class ServerThread(threading.Thread):
class ServerTestBase: class ServerTestBase:
@classmethod @classmethod
def setupAll(cls): def setupAll(cls):
cls.server = ServerThread(cls.makeserver()) cls.q = Queue.Queue()
s = cls.makeserver()
cls.port = s.port
cls.server = ServerThread(s)
cls.server.start() cls.server.start()
@classmethod @classmethod
@ -88,10 +91,7 @@ class TServer(tcp.TCPServer):
class TestServer(ServerTestBase): class TestServer(ServerTestBase):
@classmethod @classmethod
def makeserver(cls): def makeserver(cls):
cls.q = Queue.Queue() return TServer(("127.0.0.1", 0), False, cls.q, EchoHandler)
s = TServer(("127.0.0.1", 0), False, cls.q, EchoHandler)
cls.port = s.port
return s
def test_echo(self): def test_echo(self):
testval = "echo!\n" testval = "echo!\n"
@ -105,10 +105,7 @@ class TestServer(ServerTestBase):
class TestServerSSL(ServerTestBase): class TestServerSSL(ServerTestBase):
@classmethod @classmethod
def makeserver(cls): def makeserver(cls):
cls.q = Queue.Queue() return TServer(("127.0.0.1", 0), True, cls.q, EchoHandler)
s = TServer(("127.0.0.1", 0), True, cls.q, EchoHandler)
cls.port = s.port
return s
def test_echo(self): def test_echo(self):
c = tcp.TCPClient("127.0.0.1", self.port) c = tcp.TCPClient("127.0.0.1", self.port)
@ -126,10 +123,7 @@ class TestServerSSL(ServerTestBase):
class TestSSLv3Only(ServerTestBase): class TestSSLv3Only(ServerTestBase):
@classmethod @classmethod
def makeserver(cls): def makeserver(cls):
cls.q = Queue.Queue() return TServer(("127.0.0.1", 0), True, cls.q, EchoHandler, True)
s = TServer(("127.0.0.1", 0), True, cls.q, EchoHandler, True)
cls.port = s.port
return s
def test_failure(self): def test_failure(self):
c = tcp.TCPClient("127.0.0.1", self.port) c = tcp.TCPClient("127.0.0.1", self.port)
@ -140,10 +134,7 @@ class TestSSLv3Only(ServerTestBase):
class TestSNI(ServerTestBase): class TestSNI(ServerTestBase):
@classmethod @classmethod
def makeserver(cls): def makeserver(cls):
cls.q = Queue.Queue() return TServer(("127.0.0.1", 0), True, cls.q, SNIHandler)
s = TServer(("127.0.0.1", 0), True, cls.q, SNIHandler)
cls.port = s.port
return s
def test_echo(self): def test_echo(self):
c = tcp.TCPClient("127.0.0.1", self.port) c = tcp.TCPClient("127.0.0.1", self.port)
@ -155,10 +146,7 @@ class TestSNI(ServerTestBase):
class TestSSLDisconnect(ServerTestBase): class TestSSLDisconnect(ServerTestBase):
@classmethod @classmethod
def makeserver(cls): def makeserver(cls):
cls.q = Queue.Queue() return TServer(("127.0.0.1", 0), True, cls.q, DisconnectHandler)
s = TServer(("127.0.0.1", 0), True, cls.q, DisconnectHandler)
cls.port = s.port
return s
def test_echo(self): def test_echo(self):
c = tcp.TCPClient("127.0.0.1", self.port) c = tcp.TCPClient("127.0.0.1", self.port)