def testUnusedPort(self): port1 = socketutil.find_probably_unused_port() port2 = socketutil.find_probably_unused_port() assert port1 > 0 assert port1 != port2 port1 = socketutil.find_probably_unused_port( socktype=socket.SOCK_DGRAM) port2 = socketutil.find_probably_unused_port( socktype=socket.SOCK_DGRAM) assert port1 > 0 assert port1 != port2
def testUnusedPort6(self): if not has_ipv6: pytest.skip("no ipv6 capability") port1 = socketutil.find_probably_unused_port(family=socket.AF_INET6) port2 = socketutil.find_probably_unused_port(family=socket.AF_INET6) assert port1 > 0 assert port1 != port2 port1 = socketutil.find_probably_unused_port( family=socket.AF_INET6, socktype=socket.SOCK_DGRAM) port2 = socketutil.find_probably_unused_port( family=socket.AF_INET6, socktype=socket.SOCK_DGRAM) assert port1 > 0 assert port1 != port2
def testServer_multiplex(self): daemon = ServerCallback() port = socketutil.find_probably_unused_port() serv = SocketServer_Multiplex() serv.init(daemon, "localhost", port) assert serv.locationStr == "localhost:" + str(port) assert serv.sock is not None conn = socketutil.SocketConnection(serv.sock, "ID12345") assert conn.objectId == "ID12345" assert conn.sock is not None conn.close() conn.close() assert conn.sock is not None, "connections keep their socket object even if it's closed" serv.close() serv.close() assert serv.sock is None
def testServerPoolFull(self): port = socketutil.find_probably_unused_port() serv = SocketServer_Threadpool() daemon = ServerCallback() serv.init(daemon, "localhost", port) serversock = serv.sock.getsockname() csock1 = socketutil.create_socket(connect=serversock) csock2 = socketutil.create_socket(connect=serversock) try: serv.events([serv.sock]) time.sleep(0.2) assert daemon.received_denied_reasons == [None] serv.events([serv.sock]) time.sleep(0.2) assert len(daemon.received_denied_reasons) == 2 assert "no free workers, increase server threadpool size" in daemon.received_denied_reasons finally: csock1.close() csock2.close() serv.shutdown()