def test_duplicate_connection_throws_exception(ipc_base_path, runner):
    server_config = ConnectionConfig.from_name("server",
                                               base_path=ipc_base_path)
    server_done, client_done = d.checkpoint("done")

    server = d.driver(d.serve_endpoint(server_config), server_done)

    client = d.driver(
        d.run_endpoint("client"),
        d.connect_to_endpoints(server_config),
        d.wait_until_connected_to("server"),
        d.throws(d.connect_to_endpoints(server_config),
                 ConnectionAttemptRejected),
        client_done,
    )

    runner(server, client)
Esempio n. 2
0
def test_endpoint_broadcast_from_client_to_server(ipc_base_path, runner):
    server_config = ConnectionConfig.from_name("server", base_path=ipc_base_path)

    server = d.driver(d.serve_endpoint(server_config), d.wait_for(Event))

    client = d.driver(
        d.run_endpoint("client"),
        d.connect_to_endpoints(server_config),
        d.wait_any_then_broadcast(Event()),
    )

    runner(server, client)
def test_server_establishes_reverse_connection(ipc_base_path, runner):
    server_config = ConnectionConfig.from_name("server",
                                               base_path=ipc_base_path)
    server_done, client_done = d.checkpoint("done")

    server = d.driver(
        d.serve_endpoint(server_config),
        d.wait_until_connected_to("client"),
        server_done,
    )

    client = d.driver(d.run_endpoint("client"),
                      d.connect_to_endpoints(server_config), client_done)

    runner(server, client)
Esempio n. 4
0
def test_broadcast_without_listeners_explicitly_allowed(ipc_base_path, runner):
    server_config = ConnectionConfig.from_name("server", base_path=ipc_base_path)
    server_done, client_done = d.checkpoint("done")

    server = d.driver(d.serve_endpoint(server_config), server_done)

    client = d.driver(
        d.run_endpoint("client"),
        d.connect_to_endpoints(server_config),
        d.wait_until_connected_to("server"),
        d.broadcast(Event(), BroadcastConfig(require_subscriber=False)),
        client_done,
    )

    runner(server, client)
Esempio n. 5
0
def test_broadcast_without_listeners_throws(ipc_base_path, runner):
    server_config = ConnectionConfig.from_name("server", base_path=ipc_base_path)
    server_done, client_done = d.checkpoint("done")

    server = d.driver(d.serve_endpoint(server_config), server_done)

    client = d.driver(
        d.run_endpoint("client"),
        d.connect_to_endpoints(server_config),
        d.wait_until_connected_to("server"),
        d.throws(d.broadcast(Event()), NoSubscribers),
        client_done,
    )

    runner(server, client)
def test_request_response(runner, ipc_base_path):
    server_config = ConnectionConfig.from_name("server", base_path=ipc_base_path)

    received = multiprocessing.Event()

    server = d.driver(
        d.serve_endpoint(server_config),
        d.serve_request(Request, get_response=lambda endpoint, event: Response()),
    )

    client = d.driver(
        d.run_endpoint("client"),
        d.connect_to_endpoints(server_config),
        d.wait_until_any_endpoint_subscribed_to(Request),
        d.request(Request(), on_response=lambda endpoint, event: received.set()),
    )

    runner(server, client)
    assert received.is_set()
Esempio n. 7
0
async def test_endpoint_driver(ipc_base_path):
    server_config = ConnectionConfig.from_name("server",
                                               base_path=ipc_base_path)

    server_done = asyncio.Event()

    server = driver(
        serve_endpoint(server_config),
        wait_for(Event, on_event=lambda endpoint, event: server_done.set()),
    )

    client = driver(
        run_endpoint("client"),
        connect_to_endpoints(server_config),
        wait_until_any_endpoint_subscribed_to(Event),
        broadcast(Event()),
    )

    asyncio.ensure_future(server(AsyncioEngine()))
    asyncio.ensure_future(client(AsyncioEngine()))

    await asyncio.wait_for(server_done.wait(), timeout=0.1)