Beispiel #1
0
def test_get_provider_with_grace_period_grace_period_lock_acquired():
    """Test for _get_provider_with_grace_period when entry is in grace period.

    When the entry is in grace_period and we acquire the lock, we should go to the provider store
    """
    store = MockProviderStore()
    name = "material"
    provider = CachingMostRecentProvider(provider_store=store,
                                         material_name=name,
                                         version_ttl=0.0)

    provider._get_provider_with_grace_period(sentinel.version,
                                             TtlActions.GRACE_PERIOD)
    assert len(provider._cache._cache) == 1

    expected_calls = [("get_or_create_provider", name, sentinel.version)]
    assert store.provider_calls == expected_calls
Beispiel #2
0
def test_get_provider_with_grace_period_expired():
    """Test for _get_provider_with_grace_period when entry is expired.

    When the entry is expired, we should check the cache before going to the provider store.
    """
    store = MockProviderStore()
    name = "material"
    provider = CachingMostRecentProvider(provider_store=store,
                                         material_name=name,
                                         version_ttl=0.0)
    provider._cache = MagicMock()
    provider._cache.get.return_value = (sentinel.timestamp, sentinel.provider)

    test1 = provider._get_provider_with_grace_period(sentinel.version,
                                                     TtlActions.EXPIRED)
    assert test1 == sentinel.provider

    expected_calls = []
    assert store.provider_calls == expected_calls
Beispiel #3
0
def test_get_provider_with_grace_period_grace_period_lock_not_acquired():
    """Test for _get_provider_with_grace_period when entry is in grace period.

    When the entry is in grace_period and we do not acquire the lock, we should not go to the provider store
    """
    store = MockProviderStore()
    name = "material"
    provider = CachingMostRecentProvider(provider_store=store,
                                         material_name=name,
                                         version_ttl=0.0)
    provider._cache = MagicMock()
    provider._cache.get.return_value = (sentinel.timestamp, sentinel.provider)
    provider._lock = MagicMock()
    provider._lock.acquire.return_value = False

    test = provider._get_provider_with_grace_period(sentinel.version,
                                                    TtlActions.GRACE_PERIOD)
    assert test == sentinel.provider

    expected_calls = []
    assert store.provider_calls == expected_calls