Esempio n. 1
0
async def _test_asyncio_client(integration_server):
    # schedule our first coroutine (after _test_asyncio_client) in the default event loop
    future = asyncio.ensure_future(sleep_coroutine())
    client1 = get_swagger_client(integration_server, http_client.AsyncioClient())
    client2 = get_swagger_client(integration_server, http_client.AsyncioClient(),)

    # two tasks for the event loop running in a separate thread
    future1 = client1.store.getInventory()
    future2 = client2.store.getInventory()

    result = await future
    assert result == 42

    result1 = future1.response(timeout=5).result
    assert result1 == {}

    result2 = future2.response(timeout=5).result
    assert result2 == {}

    return True
def test_cancellation(integration_server):
    swagger_client = get_swagger_client(integration_server, http_client.AsyncioClient())
    bravado_future = (
        swagger_client.store.getInventory()
    )  # request takes roughly 1 second to complete
    bravado_future.cancel()

    with pytest.raises(CancelledError):
        bravado_future.result()

    bravado_future.cancel()  # make sure we can call it again without issues
Esempio n. 3
0
def test_time_until_request_done(integration_server):
    swagger_client = get_swagger_client(integration_server, http_client.AsyncioClient())
    start_time = monotonic.monotonic()
    bravado_future = swagger_client.ping.ping()
    time_waited = 0
    while not shm_request_received.value and time_waited < 1:
        time.sleep(0.01)
        time_waited += 0.01
    wait_request_received_time = monotonic.monotonic() - start_time

    bravado_future.response(timeout=1)

    assert time_waited < 0.2, "Waited {}s for request to be received by server,".format(
        wait_request_received_time
    ) + "shm value is now {}".format(shm_request_received.value)