From 13a087c416aa7a3307a8143907a129307f1e1af4 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Thu, 27 Jun 2024 15:20:40 -0700 Subject: [PATCH] PR suggestions --- python/python/tests/test_async_client.py | 43 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 5400f1d755..1a94e74dc3 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -6487,24 +6487,45 @@ async def test_lolwut(self, redis_client: TGlideClient): result = await redis_client.lolwut(2, [10, 20], RandomNode()) assert "Redis ver. " in node_result - @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("cluster_mode", [True]) @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) - async def test_random_key(self, redis_client: TGlideClient): + async def test_cluster_client_random_key(self, redis_client: TGlideClient): key = get_random_string(10) - # set a key in the database in case it was empty + # setup: delete all keys + assert isinstance(redis_client, GlideClusterClient) + assert await redis_client.flushall(FlushMode.SYNC) + + # no keys exists, so random_key returns None + assert await redis_client.random_key() is None + assert await redis_client.set(key, "foo") == OK + # `key` should be the only existing key, so random_key should return `key` + assert await redis_client.random_key() == key + assert await redis_client.random_key(AllPrimaries()) == key - result = await redis_client.random_key() - assert result is not None - assert await redis_client.exists([result]) == 1 + @pytest.mark.parametrize("cluster_mode", [False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) + async def test_standalone_client_random_key(self, redis_client: TGlideClient): + key = get_random_string(10) - if isinstance(redis_client, GlideClusterClient): - result = await redis_client.random_key(AllPrimaries()) - assert result is not None - assert await redis_client.exists([result]) == 1 + assert isinstance(redis_client, GlideClient) + # setup: delete all keys in DB 0 and DB 1 + assert await redis_client.select(0) == OK + assert await redis_client.flushdb(FlushMode.SYNC) == OK + assert await redis_client.select(1) == OK + assert await redis_client.flushdb(FlushMode.SYNC) == OK - assert await redis_client.flushall(FlushMode.SYNC) + # no keys exist so random_key returns None + assert await redis_client.random_key() is None + # set `key` in DB 1 + assert await redis_client.set(key, "foo") == OK + # `key` should be the only key in the database + assert await redis_client.random_key() == key + + # switch back to DB 0 + assert await redis_client.select(0) == OK + # DB 0 should still have no keys, so random_key should still return None assert await redis_client.random_key() is None