Exemplo n.º 1
0
async def test_cache_only_client():
    cache = MemoryCache()
    fake_client = FakeClient()
    key = 'key'
    client = CacheOnlyClient(FakeClient(), cache)

    with pytest.raises(FetchError):
        await client.fetch(key)
    cache.set(key, await fake_client.fetch(key))
    assert await client.fetch(key) == key
Exemplo n.º 2
0
async def test_simple_worker():
    keys = ['key1', 'key2', 'key3']
    dispatcher = Dispatcher(keys)
    client = FakeClient()
    worker = SimpleWorker(dispatcher, client)
    result = await worker.run()
    assert result == {key: key for key in keys}
Exemplo n.º 3
0
async def test_cache_skip_client():
    client = CacheSkipClient(FakeClient(), MemoryCache())

    key = 'key'
    assert await client.fetch(key) == key
    with pytest.raises(FetchError):
        await client.fetch(key)
Exemplo n.º 4
0
async def test_master():
    keys = ['key1', 'key2', 'key3']
    dispatcher = Dispatcher(keys)
    client = FakeClient()
    worker1 = SimpleWorker(dispatcher, client)
    worker2 = SimpleWorker(dispatcher, client)
    master = Master((worker1, worker2))
    result = await master.run()
    assert result == {key: key for key in keys}
Exemplo n.º 5
0
async def test_cache_client_broken_cache():
    client = CacheClient(FakeClient(), BrokenCache())

    key = 'key'
    with pytest.raises(OSError):
        await client.fetch(key)
Exemplo n.º 6
0
async def test_cache_client():
    client = CacheClient(FakeClient(), MemoryCache())

    key = 'key'
    assert await client.fetch(key) == key
    assert await client.fetch(key) == key
Exemplo n.º 7
0
async def test_fake_client():
    client = FakeClient()
    key = 'key'
    assert await client.fetch(key) == key
Exemplo n.º 8
0
async def test_retry_client_zero_tries():
    with pytest.raises(ValueError):
        RetryClient(FakeClient(), 0)
Exemplo n.º 9
0
async def test_cache_client():
    client = CacheClient(FakeClient(), FakeCache())

    key = 'key'
    assert key == await client.fetch(key)
    assert key == await client.fetch(key)