Skip to content

Commit

Permalink
tests: make test_client_kill_filter_by_maxage more robust
Browse files Browse the repository at this point in the history
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 <mikhail.koviazin@aiven.io>
  • Loading branch information
mkmkme committed Nov 25, 2024
1 parent f4cf4de commit 486a7b7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 486a7b7

Please sign in to comment.