From 486a7b70796872d03fb0ea77daf5e19897524d17 Mon Sep 17 00:00:00 2001 From: Mikhail Koviazin Date: Mon, 25 Nov 2024 14:30:56 +0100 Subject: [PATCH] tests: make test_client_kill_filter_by_maxage more robust Previously the test relied on the amount of clients that are currently connected to the server. This is not robust as this can be affected by the outside or a bad timing. This caused quite a lot of test case failures. The proper way to handle this is: * Create a client and assign a distinguishable name to it * Verify it's in `CLIENT LIST` * Sleep for enough time for it to be killed by maxage we provide * Verify it's not anymore in `CLIENT LIST` This commit does exactly that. Signed-off-by: Mikhail Koviazin --- tests/test_commands.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index 74b4cae2..ec8074fc 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -699,11 +699,15 @@ def test_client_kill_filter_by_user(self, r, request): @skip_if_server_version_lt("7.3.240") @pytest.mark.onlynoncluster def test_client_kill_filter_by_maxage(self, r, request): - _get_client(valkey.Valkey, request, flushdb=False) + client = _get_client(valkey.Valkey, request, flushdb=False) + client_name = "test-kill-by-maxage" + client.client_setname(client_name) time.sleep(4) - assert len(r.client_list()) >= 2 + clients = r.client_list() + assert client_name in [c["name"] for c in clients] r.client_kill_filter(maxage=2) - assert len(r.client_list()) == 1 + clients = r.client_list() + assert client_name not in [c["name"] for c in clients] @pytest.mark.onlynoncluster @skip_if_server_version_lt("2.9.50")