28 lines
710 B
Python
28 lines
710 B
Python
|
|
import pytest
|
||
|
|
|
||
|
|
from app.core import redis_sync
|
||
|
|
|
||
|
|
|
||
|
|
def test_sync_redis_reuses_singleton(monkeypatch: pytest.MonkeyPatch) -> None:
|
||
|
|
created: list[object] = []
|
||
|
|
|
||
|
|
class FakeRedis:
|
||
|
|
def close(self) -> None:
|
||
|
|
pass
|
||
|
|
|
||
|
|
def fake_from_url(*args, **kwargs):
|
||
|
|
client = FakeRedis()
|
||
|
|
created.append(client)
|
||
|
|
return client
|
||
|
|
|
||
|
|
redis_sync.reset_sync_redis_clients_for_tests()
|
||
|
|
monkeypatch.setattr(redis_sync.redis, "from_url", fake_from_url)
|
||
|
|
|
||
|
|
first = redis_sync.get_sync_redis(decode_responses=True)
|
||
|
|
second = redis_sync.get_sync_redis(decode_responses=True)
|
||
|
|
|
||
|
|
assert first is second
|
||
|
|
assert len(created) == 1
|
||
|
|
|
||
|
|
redis_sync.reset_sync_redis_clients_for_tests()
|