Skip to content

Commit 486a7b7

Browse files
author
Mikhail Koviazin
committed
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 <[email protected]>
1 parent f4cf4de commit 486a7b7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tests/test_commands.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,15 @@ def test_client_kill_filter_by_user(self, r, request):
699699
@skip_if_server_version_lt("7.3.240")
700700
@pytest.mark.onlynoncluster
701701
def test_client_kill_filter_by_maxage(self, r, request):
702-
_get_client(valkey.Valkey, request, flushdb=False)
702+
client = _get_client(valkey.Valkey, request, flushdb=False)
703+
client_name = "test-kill-by-maxage"
704+
client.client_setname(client_name)
703705
time.sleep(4)
704-
assert len(r.client_list()) >= 2
706+
clients = r.client_list()
707+
assert client_name in [c["name"] for c in clients]
705708
r.client_kill_filter(maxage=2)
706-
assert len(r.client_list()) == 1
709+
clients = r.client_list()
710+
assert client_name not in [c["name"] for c in clients]
707711

708712
@pytest.mark.onlynoncluster
709713
@skip_if_server_version_lt("2.9.50")

0 commit comments

Comments
 (0)