Example #1
0
def test_client_async_as_completed(microservice_url):
    client = RemoteService(microservice_url)

    for ready_result in as_completed(
            *[client.call_method_async("sum", [i, i + 1]) for i in range(10)]):
        print(ready_result)
        assert ready_result.finished()
Example #2
0
def test_client_async_call(microservice_url):
    client = RemoteService(microservice_url)

    async_call = client.call_method_async("sum", [1, 2])
    assert isinstance(async_call, AsyncMethodCall)
    async_call.result(wait=True)
    assert async_call.finished()
    assert async_call.result().result == 3
Example #3
0
def test_client_async_first_completed(microservice_url):
    client = RemoteService(microservice_url)

    res = first_completed(*[client.call_method_async("sum", [i, i + 1]) for i in range(10)])

    assert isinstance(res, Result)
    assert res.error is None
    assert isinstance(res.result, int)
    assert 1 <= res.result <= 19
Example #4
0
def test_async_call(monkeypatch):
    service = RemoteService(DUMMY_SERVICE_URL)
    monkeypatch.setattr(urllib.request, 'urlopen', dummy_urlopen)

    result = service.call_method_async("test", [])
    assert isinstance(result, AsyncMethodCall)

    result = result.result(wait=True)

    assert isinstance(result, Result)
    assert result.id == result.method_call.id
Example #5
0
def test_as_completed(monkeypatch):
    service = RemoteService(DUMMY_SERVICE_URL)
    monkeypatch.setattr(urllib.request, 'urlopen', dummy_urlopen)

    items = [service.call_method_async("test", []) for _ in range(10)]

    data = as_completed(*items)

    assert inspect.isgenerator(data)

    results = list(data)
    assert len(results) == 10