def test_decryption_materials_cache_expired_cache_removed(): """Tests that when the cache is expired on decrypt, we evict the entry from the cache.""" store = MockProviderStore() name = "material" provider = CachingMostRecentProvider(provider_store=store, material_name=name, version_ttl=0.0) provider._cache = MagicMock() provider._cache.get.return_value = (0.0, MagicMock()) provider.encryption_materials(sentinel.encryption_context_1) provider._cache.evict.assert_called_once()
def test_get_most_recent_version_expired(): """Test for _get_most_recent_version 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_most_recent_version(TtlActions.EXPIRED) assert test1 == sentinel.provider expected_calls = [] assert store.provider_calls == expected_calls
def test_get_most_recent_version_grace_period_lock_not_acquired(): """Test for _get_most_recent_version 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_most_recent_version(TtlActions.GRACE_PERIOD) assert test == sentinel.provider expected_calls = [] assert store.provider_calls == expected_calls