diff --git a/openslides/utils/cache_providers.py b/openslides/utils/cache_providers.py index 869c1202d..919e13722 100644 --- a/openslides/utils/cache_providers.py +++ b/openslides/utils/cache_providers.py @@ -100,9 +100,17 @@ class RedisCacheProvider: async def reset_full_cache(self, data: Dict[str, str]) -> None: """ Deletes the full_data_cache and write new data in it. + + Also deletes the restricted_data_cache and the change_id_cache. """ async with get_connection() as redis: tr = redis.multi_exec() + # like clear_cache but does not delete a lock + tr.eval( + "return redis.call('del', 'fake_key', unpack(redis.call('keys', ARGV[1])))", + keys=[], + args=["{}{}*".format(self.prefix, self.restricted_user_cache_key)]) + tr.delete(self.get_change_id_cache_key()) tr.delete(self.get_full_data_cache_key()) tr.hmset_dict(self.get_full_data_cache_key(), data) await tr.execute() diff --git a/tests/conftest.py b/tests/conftest.py index 3bb7d4d21..b99c1735a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -71,3 +71,6 @@ def reset_cache(request): # When the db is created, use the original cachables async_to_sync(element_cache.cache_provider.clear_cache)() element_cache.ensure_cache(reset=True) + + # Set constant start_time + element_cache.start_time = 1 diff --git a/tests/integration/utils/test_consumers.py b/tests/integration/utils/test_consumers.py index 5ad25b01e..64890029c 100644 --- a/tests/integration/utils/test_consumers.py +++ b/tests/integration/utils/test_consumers.py @@ -127,7 +127,7 @@ async def test_connection_with_invalid_change_id(get_communicator): @pytest.mark.asyncio async def test_connection_with_to_big_change_id(get_communicator): await set_config('general_system_enable_anonymous', True) - communicator = get_communicator('change_id=1000000000000') + communicator = get_communicator('change_id=100') connected, __ = await communicator.connect() @@ -295,7 +295,7 @@ async def test_send_get_elements_to_big_change_id(communicator): await set_config('general_system_enable_anonymous', True) await communicator.connect() - await communicator.send_json_to({'type': 'getElements', 'content': {'change_id': 1_000_000_000_000}, 'id': 'test_id'}) + await communicator.send_json_to({'type': 'getElements', 'content': {'change_id': 100}, 'id': 'test_id'}) response = await communicator.receive_json_from() type = response.get('type') @@ -346,7 +346,7 @@ async def test_send_connect_twice_with_clear_change_id_cache_same_change_id_then A client should not do this but request for change_id+1 """ await set_config('general_system_enable_anonymous', True) - element_cache.cache_provider.change_id_data = {} # type: ignore + await element_cache.cache_provider.clear_cache() await communicator.connect() await communicator.send_json_to({'type': 'getElements', 'content': {'change_id': 0}, 'id': 'test_id'}) response1 = await communicator.receive_json_from() diff --git a/tests/settings.py b/tests/settings.py index 4338177a0..4e3911bd2 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -31,6 +31,9 @@ SECRET_KEY = 'secret' DEBUG = False +# Uncomment to test with the redis cache +# REDIS_ADDRESS = "redis://127.0.0.1" + # Database # https://docs.djangoproject.com/en/1.10/ref/settings/#databases