diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_tcp.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/test/test_tcp.py b/test/test_tcp.py index cb27c63b..d6235b01 100644 --- a/test/test_tcp.py +++ b/test/test_tcp.py @@ -1,4 +1,4 @@ -import cStringIO, threading, Queue +import cStringIO, threading, Queue, time from netlib import tcp, certutils import tutils @@ -57,6 +57,12 @@ class DisconnectHandler(tcp.BaseHandler): self.close() +class HangHandler(tcp.BaseHandler): + def handle(self): + while 1: + time.sleep(1) + + class TServer(tcp.TCPServer): def __init__(self, addr, ssl, q, handler, v3_only=False): tcp.TCPServer.__init__(self, addr) @@ -188,6 +194,31 @@ class TestDisconnect(ServerTestBase): c.close() +class TestTimeOut(ServerTestBase): + @classmethod + def makeserver(cls): + return TServer(("127.0.0.1", 0), False, cls.q, HangHandler) + + def test_timeout_client(self): + c = tcp.TCPClient("127.0.0.1", self.port) + c.connect() + c.settimeout(0.1) + tutils.raises(tcp.NetLibTimeout, c.rfile.read, 10) + + +class TestSSLTimeOut(ServerTestBase): + @classmethod + def makeserver(cls): + return TServer(("127.0.0.1", 0), True, cls.q, HangHandler) + + def test_timeout_client(self): + c = tcp.TCPClient("127.0.0.1", self.port) + c.connect() + c.convert_to_ssl() + c.settimeout(0.1) + tutils.raises(tcp.NetLibTimeout, c.rfile.read, 10) + + class TestTCPClient: def test_conerr(self): c = tcp.TCPClient("127.0.0.1", 0) |