def test_retry_method_works_with_cache_overwrite(monkeypatch): redis_store = RedisStore(redis_con, TimestampRegistry(redis_con), retry_backoff=lambda: 0) global retries retries = 0 def test_cache_update(cache_entry, pipe): global retries retries += 1 redis_con.hset(cache_entry.key, "random_key", "random_value") pipe.multi() pipe.hset(cache_entry.key, "value", json.dumps(cache_entry.value)) pipe.execute() monkeypatch.setattr(redis_store, '_update_cache_entry', test_cache_update) redis_store.store("hello", "world", 0) assert redis_store.lookup("hello").value is None assert retries == 5
def test_retry_method_works_with_timestamp_overwrite(monkeypatch): ts_registry = TimestampRegistry(redis_con) redis_store = RedisStore(redis_con, ts_registry, retry_backoff=lambda: 0) global retries retries = 0 def test_cache_update(cache_entry, pipe): global retries retries += 1 ts_key = ts_registry.value_ts_key(cache_entry.key) redis_con.set(ts_key, -500) pipe.multi() pipe.set(ts_key, 5) pipe.execute() monkeypatch.setattr(redis_store, '_update_cache_entry', test_cache_update) redis_store.store("hello", "world", 0) assert redis_store.lookup("hello").value is None assert retries == 5
def test_retry_method_works_with_cache_overwrite(monkeypatch): redis_store = RedisStore( redis_con, TimestampRegistry(redis_con), retry_backoff=lambda: 0 ) global retries retries = 0 def test_cache_update(cache_entry, pipe): global retries retries += 1 redis_con.hset(cache_entry.key, "random_key", "random_value") pipe.multi() pipe.hset(cache_entry.key, "value", json.dumps(cache_entry.value)) pipe.execute() monkeypatch.setattr(redis_store, '_update_cache_entry', test_cache_update) redis_store.store("hello", "world", 0) assert redis_store.lookup("hello").value is None assert retries == 5
def test_value_is_only_written_when_newer_then_current(redis_store): registry = TimestampRegistry(redis_con) redis_store = RedisStore(redis_con, registry) redis_store.store("hello", "world", 0) assert redis_store.lookup("hello").value == "world" registry.increment_state_timestamp("hello") redis_store.store("hello", "new_world", 0) assert redis_store.lookup("hello").value == "world" redis_store.store("hello", "new_world", 1) assert redis_store.lookup("hello").value == "new_world"