async def test_trio_endpoint_as_contextmanager(): endpoint = TrioEndpoint("test") assert endpoint.is_running is False async with endpoint.run(): assert endpoint.is_running is True assert endpoint.is_running is False
async def test_connecting_to_other_trio_endpoint(ipc_base_path): config = ConnectionConfig.from_name(generate_unique_name(), base_path=ipc_base_path) async with TrioEndpoint.serve(config): async with TrioEndpoint("client").run() as client: await client.connect_to_endpoints(config) assert client.is_connected_to(config.name)
async def test_trio_duplicate_endpoint_connection_is_error(ipc_base_path): config = ConnectionConfig.from_name(generate_unique_name(), base_path=ipc_base_path) async with TrioEndpoint.serve(config): async with TrioEndpoint("client").run() as client: await client.connect_to_endpoints(config) assert client.is_connected_to(config.name) with pytest.raises(ConnectionAttemptRejected): await client.connect_to_endpoints(config)
async def test_trio_server_endpoint_establishes_reverse_connection_to_client( ipc_base_path): unique_name = generate_unique_name() config = ConnectionConfig.from_name(f"server-{unique_name}", base_path=ipc_base_path) async with TrioEndpoint.serve(config) as server: async with TrioEndpoint(f"client-{unique_name}").run() as client: await client.connect_to_endpoints(config) assert client.is_connected_to(config.name) with trio.fail_after(2): await server.wait_until_connected_to(client.name)
async def endpoint_client(endpoint_server_config, endpoint_server): async with TrioEndpoint("client-for-testing").run() as client: await client.connect_to_endpoints(endpoint_server_config) while not endpoint_server.is_connected_to("client-for-testing"): await trio.sleep(0) yield client
async def endpoint_server(endpoint_server_config): async with TrioEndpoint.serve(endpoint_server_config) as endpoint: yield endpoint
async def endpoint(nursery): async with TrioEndpoint("endpoint-for-testing").run() as client: yield client
async def test_trio_endpoint_as_contextmanager_inline(): async with TrioEndpoint("test").run() as endpoint: assert endpoint.is_running is True assert endpoint.is_running is False