Report all cache keys that were deleted

This will make it easier to add another test / feature to clear all
the cache keys. It's debatable which of "sum" and "max" is useful:

- "max" is a better (although still not accurate) indicator of the
number of "things" affected e.g. templates, services, etc.

- "sum" makes sense in places where "max" doesn't e.g. when we clear
the "organisations" group, which doesn't equate to individual orgs.

Using "sum() ... across" seems like a reasonable compromise and makes
it clear that we're iterating over different kinds of keys.

While the pluralisation is nice, I don't think it's worth the effort
to make it work for both "object(s)" and "format(s)".
This commit is contained in:
Ben Thorner
2022-02-21 10:37:51 +00:00
parent 73cc034676
commit 8396412ce1
2 changed files with 17 additions and 17 deletions

View File

@@ -745,14 +745,10 @@ def test_clear_cache_shows_form(
@pytest.mark.parametrize('model_type, expected_calls, expected_confirmation', (
('template', [
# Returns 101
call('service-????????-????-????-????-????????????-templates'),
# Returns 102
call('service-????????-????-????-????-????????????-template-????????-????-????-????-????????????-version-*'),
# Returns 103
call('service-????????-????-????-????-????????????-template-????????-????-????-????-????????????-versions'),
# 103 shown here because its the `max` of the 3 counts
], 'Removed 103 template objects from redis'),
], 'Removed 6 template objects across 3 key formats'),
('service', [
call('has_jobs-????????-????-????-????-????????????'),
call('service-????????-????-????-????-????????????'),
@@ -761,16 +757,16 @@ def test_clear_cache_shows_form(
call('service-????????-????-????-????-????????????-template-folders'),
call('service-????????-????-????-????-????????????-returned-letters-statistics'),
call('service-????????-????-????-????-????????????-returned-letters-summary'),
], 'Removed 107 service objects from redis'),
], 'Removed 14 service objects across 7 key formats'),
('organisation', [
call('organisations'),
call('domains'),
call('live-service-and-organisation-counts'),
call('organisation-????????-????-????-????-????????????-name'),
], 'Removed 104 organisation objects from redis'),
], 'Removed 8 organisation objects across 4 key formats'),
('broadcast', [
call('service-????????-????-????-????-????????????-broadcast-message-????????-????-????-????-????????????'),
], 'Removed 101 broadcast objects from redis'),
], 'Removed 2 broadcast objects across 1 key formats'),
))
def test_clear_cache_submits_and_tells_you_how_many_things_were_deleted(
client_request,
@@ -781,12 +777,14 @@ def test_clear_cache_submits_and_tells_you_how_many_things_were_deleted(
expected_confirmation,
):
redis = mocker.patch('app.main.views.platform_admin.redis_client')
# The way this is set up means the first time `delete_cache_keys_by_pattern`
# is called it will return `101`, the second time it will return `102`, etc
redis.delete_cache_keys_by_pattern.side_effect = [101, 102, 103, 104, 105, 106, 107, 108, 109]
redis.delete_cache_keys_by_pattern.return_value = 2
client_request.login(platform_admin_user)
page = client_request.post('main.clear_cache', _data={'model_type': model_type}, _expected_status=200)
page = client_request.post(
'main.clear_cache',
_data={'model_type': model_type},
_expected_status=200
)
assert redis.delete_cache_keys_by_pattern.call_args_list == expected_calls