def _set_debug_level_and_connect(): set_debug_level(10) handler = ProcessConnectionHandler() with ServerWorker(run_tcp, localhost, 0, handler=handler) as worker: with Connection.from_tcp(*worker.address) as conn: if conn.call(get_debug_level) != 10: raise AssertionError
def __run_stopping_test(self, handler): with ServerWorker(run_tcp, localhost, 0, handler=handler) as worker: conn = Connection.from_tcp(*worker.address) self.assertEqual(conn.call(add, 1, 2), 3) self.assertRaises(DisconnectError, conn.call, add, 1, 2) try: conn.close() except OSError: # Connection reset by peer on Windows pass
def test_bios_handler(self): handler = BIOSConnectionHandler() # Child process may be interrupted during interpreter shutdown, causing various errors to be # printed on stderr. Let's suppress them. with InheritableStderrCollector(): with ServerWorker(run_tcp, localhost, 0, handler=handler) as worker: with Connection.from_tcp(*worker.address) as conn: self.assertEqual(conn.call(add, 1, 2), 3) self.assertNotEqual(conn.call(os.getpid), os.getpid())
def test_multiple_connections(self): with ServerWorker(run_tcp, localhost, 0) as worker: num_conns = 5 conns = [ Connection.from_tcp(*worker.address) for _ in range(num_conns) ] for i, conn in enumerate(conns): self.assertEqual(conn.call(add, i, 1), i + 1) for conn in conns: conn.close()
def test_tcp_dual_stack(self): with ServerWorker(run_tcp, anyaddr_ipv6, 0) as worker: with Connection.from_tcp(localhost, worker.address[1]) as conn: self.assertEqual(conn.call(add, 1, 2), 3)
def test_tcp_ipv6(self): with ServerWorker(run_tcp, localhost_ipv6, 0) as worker: with Connection.from_tcp(*worker.address[:2]) as conn: self.assertEqual(conn.call(add, 1, 2), 3)