Пример #1
0
 async def test_ack_deadline_cache_get_no_call_if_not_outdated(
         subscriber_client):
     cache = AckDeadlineCache(subscriber_client, 'fake_subscription', 1000)
     cache.ack_deadline = 33
     cache.last_refresh = time.perf_counter()
     assert await cache.get() == 33
     subscriber_client.get_subscription.assert_not_called()
Пример #2
0
 async def test_ack_deadline_cache_get_refreshes_if_outdated(
         subscriber_client):
     cache = AckDeadlineCache(subscriber_client, 'fake_subscription', 0)
     cache.ack_deadline = 33
     assert await cache.get() == 42
     assert cache.last_refresh
     subscriber_client.get_subscription.assert_called_once()
Пример #3
0
 async def test_ack_deadline_cache_refresh_is_cool_about_failures(
         subscriber_client):
     f = asyncio.Future()
     f.set_exception(RuntimeError)
     subscriber_client.get_subscription = MagicMock(return_value=f)
     cache = AckDeadlineCache(subscriber_client, 'fake_subscription', 1)
     cache.ack_deadline = 55.0
     await cache.refresh()
     assert cache.ack_deadline == 55.0
     assert cache.last_refresh
Пример #4
0
    async def test_ack_deadline_cache_cache_outdated_true(subscriber_client):
        cache = AckDeadlineCache(
            subscriber_client, 'fake_subscription', 0)
        cache.last_refresh = time.perf_counter()
        assert cache.cache_outdated()

        cache = AckDeadlineCache(
            subscriber_client, 'fake_subscription', 1000)
        cache.last_refresh = time.perf_counter()
        cache.ack_deadline = float('inf')
        assert cache.cache_outdated()
Пример #5
0
 async def test_ack_deadline_cache_cache_outdated_false(subscriber_client):
     cache = AckDeadlineCache(
         subscriber_client, 'fake_subscription', 1000)
     cache.ack_deadline = 10
     cache.last_refresh = time.perf_counter()
     assert not cache.cache_outdated()