test tcpclient.source_address, increase coverage
This commit is contained in:
parent
9ea4646262
commit
0187d92ec0
|
@ -1,4 +1,4 @@
|
|||
import cStringIO, Queue, time, socket
|
||||
import cStringIO, Queue, time, socket, random
|
||||
from netlib import tcp, certutils, test
|
||||
import mock
|
||||
import tutils
|
||||
|
@ -24,6 +24,12 @@ class EchoHandler(tcp.BaseHandler):
|
|||
self.wfile.flush()
|
||||
|
||||
|
||||
class ClientPeernameHandler(tcp.BaseHandler):
|
||||
def handle(self):
|
||||
self.wfile.write(str(self.connection.getpeername()))
|
||||
self.wfile.flush()
|
||||
|
||||
|
||||
class CertHandler(tcp.BaseHandler):
|
||||
sni = None
|
||||
def handle_sni(self, connection):
|
||||
|
@ -74,6 +80,22 @@ class TestServer(test.ServerTestBase):
|
|||
assert c.rfile.readline() == testval
|
||||
|
||||
|
||||
class TestServerBind(test.ServerTestBase):
|
||||
handler = ClientPeernameHandler
|
||||
|
||||
def test_bind(self):
|
||||
""" Test to bind to a given random port. Try again if the random port turned out to be blocked. """
|
||||
for i in range(20):
|
||||
random_port = random.randrange(1024, 65535)
|
||||
try:
|
||||
c = tcp.TCPClient("127.0.0.1", self.port, source_address=("127.0.0.1", random_port))
|
||||
c.connect()
|
||||
assert c.rfile.readline() == str(("127.0.0.1", random_port))
|
||||
return
|
||||
except tcp.NetLibError: # port probably already in use
|
||||
pass
|
||||
|
||||
|
||||
class TestServerIPv6(test.ServerTestBase):
|
||||
handler = EchoHandler
|
||||
use_ipv6 = True
|
||||
|
|
Loading…
Reference in New Issue