Exemplo n.º 1
0
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)
Exemplo n.º 2
0
async def test_wait_until_connected_to(endpoint):
    config = ConnectionConfig.from_name(generate_unique_name())
    async with AsyncioEndpoint.serve(config):
        asyncio.ensure_future(endpoint.connect_to_endpoints(config))

        assert not endpoint.is_connected_to(config.name)
        await endpoint.wait_until_connected_to(config.name)
        assert endpoint.is_connected_to(config.name)
Exemplo n.º 3
0
async def test_rejects_duplicates_when_connecting():
    own = ConnectionConfig.from_name(generate_unique_name())
    async with AsyncioEndpoint.serve(own) as endpoint:
        await endpoint.connect_to_endpoint(own)

        assert endpoint.is_connected_to(own.name)
        with pytest.raises(ConnectionAttemptRejected):
            await endpoint.connect_to_endpoint(own)
Exemplo n.º 4
0
async def test_endpoint_serve(ipc_base_path):
    config = ConnectionConfig.from_name(generate_unique_name(), base_path=ipc_base_path)
    async with AsyncioEndpoint.serve(config) as endpoint:
        assert endpoint.is_running is True
        assert endpoint.is_serving is True

    assert endpoint.is_running is False
    assert endpoint.is_serving is False
async def test_base_wait_until_connections_changed():
    config = ConnectionConfig.from_name(generate_unique_name())
    async with AsyncioEndpoint.serve(config):
        async with AsyncioEndpoint("client").run() as client:
            asyncio.ensure_future(client.connect_to_endpoints(config))

            assert not client.is_connected_to(config.name)
            await asyncio.wait_for(client.wait_until_connections_change(),
                                   timeout=0.1)
            assert client.is_connected_to(config.name)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
async def test_endpoint_serve_with_error(ipc_base_path):
    config = ConnectionConfig.from_name(generate_unique_name(), base_path=ipc_base_path)

    with pytest.raises(Exception, match="break out of serve"):
        async with AsyncioEndpoint.serve(config) as endpoint:
            assert endpoint.is_running is True
            assert endpoint.is_serving is True
            raise Exception("break out of serve")

    assert endpoint.is_running is False
    assert endpoint.is_serving is False
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 test_base_wait_until_any_endpoint_subscriptions_changed():
    config = ConnectionConfig.from_name(generate_unique_name())
    async with AsyncioEndpoint.serve(config) as server:
        async with AsyncioEndpoint("client").run() as client:
            await client.connect_to_endpoints(config)
            assert client.is_connected_to(config.name)

            server.subscribe(SubscriptionEvent, lambda e: None)

            assert not client.is_any_endpoint_subscribed_to(SubscriptionEvent)
            await asyncio.wait_for(
                client.wait_until_endpoint_subscriptions_change(), timeout=0.1
            )
            assert client.is_any_endpoint_subscribed_to(SubscriptionEvent)
Exemplo n.º 10
0
async def test_connect_to_endpoint():
    config = ConnectionConfig.from_name(generate_unique_name())
    async with AsyncioEndpoint.serve(config):
        async with AsyncioEndpoint("client").run() as client:
            await client.connect_to_endpoint(config)
            assert client.is_connected_to(config.name)
Exemplo n.º 11
0
async def test_connect_to_endpoint(endpoint):
    config = ConnectionConfig.from_name(generate_unique_name())
    async with AsyncioEndpoint.serve(config):
        await endpoint.connect_to_endpoints(config)
        assert endpoint.is_connected_to(config.name)
Exemplo n.º 12
0
async def test_server_establishes_reverse_connection(endpoint):
    config = ConnectionConfig.from_name(generate_unique_name())
    async with AsyncioEndpoint.serve(config) as server:
        await endpoint.connect_to_endpoints(config)
        assert endpoint.is_connected_to(config.name)
        assert server.is_connected_to(endpoint.name)