def test_tcp_connect_closed_port(Poller, ipv6): ### FIXME: This test is wrong. ### We need to figure out the sequence of events on Windows ### for this scenario. I think if you attempt to connect to ### a shutdown listening socket (tcp server) you should get ### an error event as response. if pytest.PLATFORM == "win32": pytest.skip("Broken on Windows") m = Manager() + Poller() if ipv6: tcp_server = TCP6Server(("::1", 0)) tcp_client = TCP6Client() else: tcp_server = TCPServer(0) tcp_client = TCPClient() server = Server() + tcp_server client = Client() + tcp_client server.register(m) client.register(m) m.start() try: assert pytest.wait_for(client, "ready") assert pytest.wait_for(server, "ready") wait_host(server) host, port = server.host, server.port tcp_server._sock.close() # 1st connect client.fire(connect(host, port)) assert pytest.wait_for(client, "connected") assert isinstance(client.error, SocketError) client.fire(write(b"foo")) assert pytest.wait_for(client, "disconnected") client.disconnected = False client.fire(write(b"foo")) assert pytest.wait_for(client, "disconnected", timeout=1.0) is None finally: m.stop()
def test_tcps_basic(Poller, ipv6): from circuits import Debugger m = Manager() + Debugger() + Poller() if ipv6: tcp_server = TCP6Server(("::1", 0), secure=True, certfile=CERT_FILE) tcp_client = TCP6Client() else: tcp_server = TCPServer(0, secure=True, certfile=CERT_FILE) tcp_client = TCPClient() server = Server() + tcp_server client = Client() + tcp_client server.register(m) client.register(m) m.start() try: assert pytest.wait_for(client, "ready") assert pytest.wait_for(server, "ready") wait_host(server) client.fire(connect(server.host, server.port, secure=True)) assert pytest.wait_for(client, "connected") assert pytest.wait_for(server, "connected") assert pytest.wait_for(client, "data", b"Ready") client.fire(write(b"foo")) assert pytest.wait_for(server, "data", b"foo") assert pytest.wait_for(client, "data", b"foo") client.fire(close()) assert pytest.wait_for(client, "disconnected") assert pytest.wait_for(server, "disconnected") server.fire(close()) assert pytest.wait_for(server, "closed") finally: m.stop()