From 6446967bd4591ca0c159e5866cefabd03963648a Mon Sep 17 00:00:00 2001 From: Shachar Langbeheim Date: Sat, 10 Feb 2024 21:12:22 +0200 Subject: [PATCH] Parameterize Python tests for both RESP2 & RESP3. (#910) * Parameterize Python tests for both RESP2 & RESP3. * use split parameters --- python/python/tests/conftest.py | 4 +- python/python/tests/test_async_client.py | 88 ++++++++++++++++++++--- python/python/tests/test_redis_modules.py | 3 + python/python/tests/test_transaction.py | 35 +++------ 4 files changed, 92 insertions(+), 38 deletions(-) diff --git a/python/python/tests/conftest.py b/python/python/tests/conftest.py index 0fca384727..359dab6ee2 100644 --- a/python/python/tests/conftest.py +++ b/python/python/tests/conftest.py @@ -95,10 +95,10 @@ def pytest_sessionfinish(session, exitstatus): @pytest.fixture() async def redis_client( - request, cluster_mode: bool + request, cluster_mode: bool, protocol: ProtocolVersion ) -> AsyncGenerator[TRedisClient, None]: "Get async socket client for tests" - client = await create_client(request, cluster_mode) + client = await create_client(request, cluster_mode, protocol=protocol) yield client await client.close() diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index ee2b0b96d9..ffc0bca23e 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -107,6 +107,7 @@ async def check_if_server_version_lt(client: TRedisClient, min_version: str) -> @pytest.mark.asyncio class TestRedisClients: @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_register_client_name_and_version(self, redis_client: TRedisClient): min_version = "7.2.0" if await check_if_server_version_lt(redis_client, min_version): @@ -118,6 +119,7 @@ async def test_register_client_name_and_version(self, redis_client: TRedisClient assert "lib-ver=0.1.0" in info @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_send_and_receive_large_values(self, redis_client: TRedisClient): length = 2**16 key = get_random_string(length) @@ -128,6 +130,7 @@ async def test_send_and_receive_large_values(self, redis_client: TRedisClient): assert await redis_client.get(key) == value @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_send_and_receive_non_ascii_unicode(self, redis_client: TRedisClient): key = "foo" value = "שלום hello 汉字" @@ -137,6 +140,7 @@ async def test_send_and_receive_non_ascii_unicode(self, redis_client: TRedisClie @pytest.mark.parametrize("value_size", [100, 2**16]) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_client_handle_concurrent_workload_without_dropping_or_changing_values( self, redis_client: TRedisClient, value_size ): @@ -157,6 +161,7 @@ async def exec_command(i): await asyncio.gather(*(list(running_tasks))) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_can_connect_with_auth_requirepass( self, redis_client: TRedisClient, request ): @@ -197,6 +202,7 @@ async def test_can_connect_with_auth_requirepass( await auth_client.custom_command(["CONFIG", "SET", "requirepass", ""]) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_can_connect_with_auth_acl( self, redis_client: Union[RedisClient, RedisClusterClient], request ): @@ -247,14 +253,19 @@ async def test_select_standalone_database_id(self, request): assert "db=4" in client_info @pytest.mark.parametrize("cluster_mode", [True, False]) - async def test_client_name(self, request, cluster_mode): + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) + async def test_client_name(self, request, cluster_mode, protocol): redis_client = await create_client( - request, cluster_mode=cluster_mode, client_name="TEST_CLIENT_NAME" + request, + cluster_mode=cluster_mode, + client_name="TEST_CLIENT_NAME", + protocol=protocol, ) client_info = await redis_client.custom_command(["CLIENT", "INFO"]) assert "name=TEST_CLIENT_NAME" in client_info @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_closed_client_raises_error(self, redis_client: TRedisClient): await redis_client.close() with pytest.raises(ClosingError) as e: @@ -266,6 +277,7 @@ async def test_closed_client_raises_error(self, redis_client: TRedisClient): class TestCommands: @pytest.mark.smoke_test @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_socket_set_get(self, redis_client: TRedisClient): key = get_random_string(10) value = datetime.now(timezone.utc).strftime("%m/%d/%Y, %H:%M:%S") @@ -273,24 +285,21 @@ async def test_socket_set_get(self, redis_client: TRedisClient): assert await redis_client.get(key) == value @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP3]) async def test_use_resp3_protocol(self, redis_client: TRedisClient): result = cast(Dict[str, str], await redis_client.custom_command(["HELLO"])) assert int(result["proto"]) == 3 @pytest.mark.parametrize("cluster_mode", [True, False]) - async def test_allow_opt_in_to_resp2_protocol(self, cluster_mode, request): - redis_client = await create_client( - request, - cluster_mode, - protocol=ProtocolVersion.RESP2, - ) - + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2]) + async def test_allow_opt_in_to_resp2_protocol(self, redis_client: TRedisClient): result = cast(Dict[str, str], await redis_client.custom_command(["HELLO"])) assert int(result["proto"]) == 2 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_conditional_set(self, redis_client: TRedisClient): key = get_random_string(10) value = get_random_string(10) @@ -310,6 +319,7 @@ async def test_conditional_set(self, redis_client: TRedisClient): assert await redis_client.get(key) == value @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_set_return_old_value(self, redis_client: TRedisClient): min_version = "6.2.0" if await check_if_server_version_lt(redis_client, min_version): @@ -326,12 +336,14 @@ async def test_set_return_old_value(self, redis_client: TRedisClient): assert await redis_client.get(key) == new_value @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_custom_command_single_arg(self, redis_client: TRedisClient): # Test single arg command res = await redis_client.custom_command(["PING"]) assert res == "PONG" @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_custom_command_multi_arg(self, redis_client: TRedisClient): # Test multi args command client_list = await redis_client.custom_command( @@ -344,6 +356,7 @@ async def test_custom_command_multi_arg(self, redis_client: TRedisClient): assert "cmd=client" in res @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_custom_command_lower_and_upper_case( self, redis_client: TRedisClient ): @@ -358,6 +371,7 @@ async def test_custom_command_lower_and_upper_case( assert "cmd=client" in res @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_request_error_raises_exception(self, redis_client: TRedisClient): key = get_random_string(10) value = get_random_string(10) @@ -367,6 +381,7 @@ async def test_request_error_raises_exception(self, redis_client: TRedisClient): assert "WRONGTYPE" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_info_server_replication(self, redis_client: TRedisClient): info = get_first_result(await redis_client.info([InfoSection.SERVER])) assert "# Server" in info @@ -378,6 +393,7 @@ async def test_info_server_replication(self, redis_client: TRedisClient): assert "# Errorstats" not in info @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_info_default(self, redis_client: TRedisClient): cluster_mode = isinstance(redis_client, RedisClusterClient) info_result = await redis_client.info() @@ -391,6 +407,7 @@ async def test_info_default(self, redis_client: TRedisClient): assert "# Memory" in info_result @pytest.mark.parametrize("cluster_mode", [False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_select(self, redis_client: RedisClient): assert await redis_client.select(0) == OK key = get_random_string(10) @@ -403,6 +420,7 @@ async def test_select(self, redis_client: RedisClient): assert await redis_client.get(key) == value @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_delete(self, redis_client: TRedisClient): keys = [get_random_string(10), get_random_string(10), get_random_string(10)] value = get_random_string(10) @@ -415,6 +433,7 @@ async def test_delete(self, redis_client: TRedisClient): assert await redis_client.delete(keys) == 0 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_config_reset_stat(self, redis_client: TRedisClient): # we execute set and info so the total_commands_processed will be greater than 1 # after the configResetStat call we initiate an info command and the the total_commands_processed will be 1. @@ -432,6 +451,7 @@ async def test_config_reset_stat(self, redis_client: TRedisClient): assert info_stats["total_commands_processed"] == "1" @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_config_rewrite(self, redis_client: TRedisClient): info_server = parse_info_response( get_first_result(await redis_client.info([InfoSection.SERVER])) @@ -445,12 +465,14 @@ async def test_config_rewrite(self, redis_client: TRedisClient): assert "The server is running without a config file" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_client_id(self, redis_client: TRedisClient): client_id = await redis_client.client_id() assert type(client_id) is int assert client_id > 0 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_incr_commands_existing_key(self, redis_client: TRedisClient): key = get_random_string(10) assert await redis_client.set(key, "10") == OK @@ -462,6 +484,7 @@ async def test_incr_commands_existing_key(self, redis_client: TRedisClient): assert await redis_client.get(key) == "20.5" @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_incr_commands_non_existing_key(self, redis_client: TRedisClient): key = get_random_string(10) key2 = get_random_string(10) @@ -480,6 +503,7 @@ async def test_incr_commands_non_existing_key(self, redis_client: TRedisClient): assert await redis_client.get(key3) == "0.5" @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_incr_commands_with_str_value(self, redis_client: TRedisClient): key = get_random_string(10) assert await redis_client.set(key, "foo") == OK @@ -498,6 +522,7 @@ async def test_incr_commands_with_str_value(self, redis_client: TRedisClient): assert "value is not a valid float" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_client_getname(self, redis_client: TRedisClient): assert await redis_client.client_getname() is None assert ( @@ -507,6 +532,7 @@ async def test_client_getname(self, redis_client: TRedisClient): assert await redis_client.client_getname() == "GlideConnection" @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_mset_mget(self, redis_client: TRedisClient): keys = [get_random_string(10), get_random_string(10), get_random_string(10)] non_existing_key = get_random_string(10) @@ -521,11 +547,13 @@ async def test_mset_mget(self, redis_client: TRedisClient): assert mget_res == keys @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_ping(self, redis_client: TRedisClient): assert await redis_client.ping() == "PONG" assert await redis_client.ping("HELLO") == "HELLO" @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_config_get_set(self, redis_client: TRedisClient): previous_timeout = await redis_client.config_get(["timeout"]) assert await redis_client.config_set({"timeout": "1000"}) == OK @@ -539,6 +567,7 @@ async def test_config_get_set(self, redis_client: TRedisClient): ) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_decr_decrby_existing_key(self, redis_client: TRedisClient): key = get_random_string(10) assert await redis_client.set(key, "10") == OK @@ -548,6 +577,7 @@ async def test_decr_decrby_existing_key(self, redis_client: TRedisClient): assert await redis_client.get(key) == "5" @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_decr_decrby_non_existing_key(self, redis_client: TRedisClient): key = get_random_string(10) key2 = get_random_string(10) @@ -561,6 +591,7 @@ async def test_decr_decrby_non_existing_key(self, redis_client: TRedisClient): assert await redis_client.get(key2) == "-3" @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_decr_with_str_value(self, redis_client: TRedisClient): key = get_random_string(10) assert await redis_client.set(key, "foo") == OK @@ -575,6 +606,7 @@ async def test_decr_with_str_value(self, redis_client: TRedisClient): assert "value is not an integer" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_hset_hget_hgetall(self, redis_client: TRedisClient): key = get_random_string(10) field = get_random_string(5) @@ -590,6 +622,7 @@ async def test_hset_hget_hgetall(self, redis_client: TRedisClient): assert await redis_client.hgetall("non_existing_field") == {} @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_hdel(self, redis_client: TRedisClient): key = get_random_string(10) field = get_random_string(5) @@ -603,6 +636,7 @@ async def test_hdel(self, redis_client: TRedisClient): assert await redis_client.hdel("nonExistingKey", [field3]) == 0 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_hmget(self, redis_client: TRedisClient): key = get_random_string(10) field = get_random_string(5) @@ -621,6 +655,7 @@ async def test_hmget(self, redis_client: TRedisClient): ] @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_hset_without_data(self, redis_client: TRedisClient): with pytest.raises(RequestError) as e: await redis_client.hset("key", {}) @@ -628,6 +663,7 @@ async def test_hset_without_data(self, redis_client: TRedisClient): assert "wrong number of arguments" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_hincrby_hincrbyfloat(self, redis_client: TRedisClient): key = get_random_string(10) field = get_random_string(5) @@ -639,6 +675,7 @@ async def test_hincrby_hincrbyfloat(self, redis_client: TRedisClient): assert await redis_client.hincrbyfloat(key, field, 1.5) == 16.5 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_hincrby_non_existing_key_field(self, redis_client: TRedisClient): key = get_random_string(10) key2 = get_random_string(10) @@ -652,6 +689,7 @@ async def test_hincrby_non_existing_key_field(self, redis_client: TRedisClient): assert await redis_client.hincrbyfloat(key2, "nonExistingField", -0.5) == -0.5 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_hincrby_invalid_value(self, redis_client: TRedisClient): key = get_random_string(10) field = get_random_string(5) @@ -668,6 +706,7 @@ async def test_hincrby_invalid_value(self, redis_client: TRedisClient): assert "hash value is not a float" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_hexist(self, redis_client: TRedisClient): key = get_random_string(10) field = get_random_string(5) @@ -680,6 +719,7 @@ async def test_hexist(self, redis_client: TRedisClient): assert await redis_client.hexists("nonExistingKey", field2) == False @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_lpush_lpop_lrange(self, redis_client: TRedisClient): key = get_random_string(10) value_list = ["value4", "value3", "value2", "value1"] @@ -692,6 +732,7 @@ async def test_lpush_lpop_lrange(self, redis_client: TRedisClient): assert await redis_client.lpop("non_existing_key") is None @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_lpush_lpop_lrange_wrong_type_raise_error( self, redis_client: TRedisClient ): @@ -711,6 +752,7 @@ async def test_lpush_lpop_lrange_wrong_type_raise_error( assert "Operation against a key holding the wrong kind of value" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_rpush_rpop(self, redis_client: TRedisClient): key = get_random_string(10) value_list = ["value4", "value3", "value2", "value1"] @@ -722,6 +764,7 @@ async def test_rpush_rpop(self, redis_client: TRedisClient): assert await redis_client.rpop("non_existing_key") is None @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_rpush_rpop_wrong_type_raise_error(self, redis_client: TRedisClient): key = get_random_string(10) assert await redis_client.set(key, "foo") == OK @@ -735,6 +778,7 @@ async def test_rpush_rpop_wrong_type_raise_error(self, redis_client: TRedisClien assert "Operation against a key holding the wrong kind of value" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_sadd_srem_smembers_scard(self, redis_client: TRedisClient): key = get_random_string(10) value_list = ["member1", "member2", "member3", "member4"] @@ -748,6 +792,7 @@ async def test_sadd_srem_smembers_scard(self, redis_client: TRedisClient): assert await redis_client.scard(key) == 2 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_sadd_srem_smembers_scard_non_existing_key( self, redis_client: TRedisClient ): @@ -757,6 +802,7 @@ async def test_sadd_srem_smembers_scard_non_existing_key( assert await redis_client.smembers(non_existing_key) == set() @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_sadd_srem_smembers_scard_wrong_type_raise_error( self, redis_client: TRedisClient ): @@ -780,6 +826,7 @@ async def test_sadd_srem_smembers_scard_wrong_type_raise_error( assert "Operation against a key holding the wrong kind of value" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_ltrim(self, redis_client: TRedisClient): key = get_random_string(10) value_list = ["value4", "value3", "value2", "value1"] @@ -799,6 +846,7 @@ async def test_ltrim(self, redis_client: TRedisClient): assert "Operation against a key holding the wrong kind of value" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_lrem(self, redis_client: TRedisClient): key = get_random_string(10) value_list = ["value1", "value2", "value1", "value1", "value2"] @@ -817,6 +865,7 @@ async def test_lrem(self, redis_client: TRedisClient): assert await redis_client.lrem("non_existing_key", 2, "value") == 0 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_llen(self, redis_client: TRedisClient): key1 = get_random_string(10) key2 = get_random_string(10) @@ -833,6 +882,7 @@ async def test_llen(self, redis_client: TRedisClient): assert "Operation against a key holding the wrong kind of value" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_exists(self, redis_client: TRedisClient): keys = [get_random_string(10), get_random_string(10)] @@ -845,6 +895,7 @@ async def test_exists(self, redis_client: TRedisClient): assert await redis_client.exists(keys) == 2 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_unlink(self, redis_client: TRedisClient): key1 = get_random_string(10) key2 = get_random_string(10) @@ -856,6 +907,7 @@ async def test_unlink(self, redis_client: TRedisClient): assert await redis_client.unlink([key1, key2, "non_existing_key", key3]) == 3 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_expire_pexpire_ttl_with_positive_timeout( self, redis_client: TRedisClient ): @@ -886,6 +938,7 @@ async def test_expire_pexpire_ttl_with_positive_timeout( assert await redis_client.ttl(key) in range(16) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_expireat_pexpireat_ttl_with_positive_timeout( self, redis_client: TRedisClient ): @@ -918,6 +971,7 @@ async def test_expireat_pexpireat_ttl_with_positive_timeout( ) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_expire_pexpire_expireat_pexpireat_past_or_negative_timeout( self, redis_client: TRedisClient ): @@ -943,6 +997,7 @@ async def test_expire_pexpire_expireat_pexpireat_past_or_negative_timeout( assert await redis_client.ttl(key) == -2 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_expire_pexpire_expireAt_pexpireAt_ttl_non_existing_key( self, redis_client: TRedisClient ): @@ -957,6 +1012,7 @@ async def test_expire_pexpire_expireAt_pexpireAt_ttl_non_existing_key( assert await redis_client.ttl(key) == -2 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_zadd_zaddincr(self, redis_client: TRedisClient): key = get_random_string(10) members_scores = {"one": 1, "two": 2, "three": 3} @@ -964,6 +1020,7 @@ async def test_zadd_zaddincr(self, redis_client: TRedisClient): assert await redis_client.zadd_incr(key, member="one", increment=2) == 3.0 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_zadd_nx_xx(self, redis_client: TRedisClient): key = get_random_string(10) members_scores = {"one": 1, "two": 2, "three": 3} @@ -1005,6 +1062,7 @@ async def test_zadd_nx_xx(self, redis_client: TRedisClient): ) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_zadd_gt_lt(self, redis_client: TRedisClient): key = get_random_string(10) members_scores = {"one": -3, "two": 2, "three": 3} @@ -1051,6 +1109,7 @@ async def test_zadd_gt_lt(self, redis_client: TRedisClient): ) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_zrem(self, redis_client: TRedisClient): key = get_random_string(10) members_scores = {"one": 1, "two": 2, "three": 3} @@ -1062,6 +1121,7 @@ async def test_zrem(self, redis_client: TRedisClient): assert await redis_client.zrem("non_existing_set", ["member"]) == 0 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_zcard(self, redis_client: TRedisClient): key = get_random_string(10) members_scores = {"one": 1, "two": 2, "three": 3} @@ -1073,6 +1133,7 @@ async def test_zcard(self, redis_client: TRedisClient): assert await redis_client.zcard("non_existing_key") == 0 @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_zcount(self, redis_client: TRedisClient): key = get_random_string(10) members_scores = {"one": 1, "two": 2, "three": 3} @@ -1101,6 +1162,7 @@ async def test_zcount(self, redis_client: TRedisClient): ) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_zscore(self, redis_client: TRedisClient): key = get_random_string(10) members_scores = {"one": 1, "two": 2, "three": 3} @@ -1197,12 +1259,14 @@ async def cluster_route_custom_command_multi_nodes( assert replica_count == expected_replica_count @pytest.mark.parametrize("cluster_mode", [True]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_cluster_route_custom_command_all_nodes( self, redis_client: RedisClusterClient ): await self.cluster_route_custom_command_multi_nodes(redis_client, AllNodes()) @pytest.mark.parametrize("cluster_mode", [True]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_cluster_route_custom_command_all_primaries( self, redis_client: RedisClusterClient ): @@ -1211,6 +1275,7 @@ async def test_cluster_route_custom_command_all_primaries( ) @pytest.mark.parametrize("cluster_mode", [True]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_cluster_route_custom_command_random_node( self, redis_client: RedisClusterClient ): @@ -1246,18 +1311,21 @@ async def cluster_route_custom_command_slot_route( assert primary_node_id == expected_primary_node_id @pytest.mark.parametrize("cluster_mode", [True]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_cluster_route_custom_command_slot_key_route( self, redis_client: RedisClusterClient ): await self.cluster_route_custom_command_slot_route(redis_client, True) @pytest.mark.parametrize("cluster_mode", [True]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_cluster_route_custom_command_slot_id_route( self, redis_client: RedisClusterClient ): await self.cluster_route_custom_command_slot_route(redis_client, False) @pytest.mark.parametrize("cluster_mode", [True]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_info_random_route(self, redis_client: RedisClusterClient): info = await redis_client.info([InfoSection.SERVER], RandomNode()) assert isinstance(info, str) @@ -1268,6 +1336,7 @@ async def test_info_random_route(self, redis_client: RedisClusterClient): @pytest.mark.asyncio class TestExceptions: @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_timeout_exception_with_blpop(self, redis_client: TRedisClient): key = get_random_string(10) with pytest.raises(TimeoutError) as e: @@ -1278,6 +1347,7 @@ async def test_timeout_exception_with_blpop(self, redis_client: TRedisClient): class TestScripts: @pytest.mark.smoke_test @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_script(self, redis_client: TRedisClient): key1 = get_random_string(10) key2 = get_random_string(10) diff --git a/python/python/tests/test_redis_modules.py b/python/python/tests/test_redis_modules.py index 1974ee3e48..559bacfcdb 100644 --- a/python/python/tests/test_redis_modules.py +++ b/python/python/tests/test_redis_modules.py @@ -2,6 +2,7 @@ import pytest from glide.async_commands.core import InfoSection +from glide.config import ProtocolVersion from glide.redis_client import TRedisClient from tests.test_async_client import parse_info_response @@ -9,11 +10,13 @@ @pytest.mark.asyncio class TestRedisModules: @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_search_module_loaded(self, redis_client: TRedisClient): res = parse_info_response(await redis_client.info([InfoSection.MODULES])) assert "search" in res["module"] @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_json_module_loadded(self, redis_client: TRedisClient): res = parse_info_response(await redis_client.info([InfoSection.MODULES])) assert "ReJSON" in res["module"] diff --git a/python/python/tests/test_transaction.py b/python/python/tests/test_transaction.py index cadf06b7c2..4840f94399 100644 --- a/python/python/tests/test_transaction.py +++ b/python/python/tests/test_transaction.py @@ -147,6 +147,7 @@ def transaction_test( @pytest.mark.asyncio class TestTransaction: @pytest.mark.parametrize("cluster_mode", [True]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_transaction_with_different_slots(self, redis_client: TRedisClient): transaction = ( Transaction() @@ -160,6 +161,7 @@ async def test_transaction_with_different_slots(self, redis_client: TRedisClient assert "Moved" in str(e) @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_transaction_custom_command(self, redis_client: TRedisClient): key = get_random_string(10) transaction = ( @@ -173,6 +175,7 @@ async def test_transaction_custom_command(self, redis_client: TRedisClient): assert result == [1, "bar"] @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_transaction_custom_unsupported_command( self, redis_client: TRedisClient ): @@ -190,6 +193,7 @@ async def test_transaction_custom_unsupported_command( ) # TODO : add an assert on EXEC ABORT @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_transaction_discard_command(self, redis_client: TRedisClient): key = get_random_string(10) await redis_client.set(key, "1") @@ -208,6 +212,7 @@ async def test_transaction_discard_command(self, redis_client: TRedisClient): assert value == "1" @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_transaction_exec_abort(self, redis_client: TRedisClient): key = get_random_string(10) transaction = BaseTransaction() @@ -219,6 +224,7 @@ async def test_transaction_exec_abort(self, redis_client: TRedisClient): ) # TODO : add an assert on EXEC ABORT @pytest.mark.parametrize("cluster_mode", [True]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_cluster_transaction(self, redis_client: RedisClusterClient): keyslot = get_random_string(3) transaction = ClusterTransaction() @@ -231,6 +237,7 @@ async def test_cluster_transaction(self, redis_client: RedisClusterClient): assert result[1:] == expected @pytest.mark.parametrize("cluster_mode", [True, False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_can_return_null_on_watch_transaction_failures( self, redis_client: TRedisClient, request ): @@ -254,6 +261,7 @@ async def test_can_return_null_on_watch_transaction_failures( await client2.close() @pytest.mark.parametrize("cluster_mode", [False]) + @pytest.mark.parametrize("protocol", [ProtocolVersion.RESP2, ProtocolVersion.RESP3]) async def test_standalone_transaction(self, redis_client: RedisClient): keyslot = get_random_string(3) key = "{{{}}}:{}".format(keyslot, get_random_string(3)) # to get the same slot @@ -273,33 +281,6 @@ async def test_standalone_transaction(self, redis_client: RedisClient): assert result[1:6] == [OK, OK, value, OK, None] assert result[6:] == expected - # this test ensures that all types in RESP2 are converted to their RESP3 equivalent. - @pytest.mark.parametrize("cluster_mode", [False]) - async def test_standalone_transaction_on_resp2(self, cluster_mode, request): - redis_client = await create_client( - request, - cluster_mode, - protocol=ProtocolVersion.RESP2, - ) - - keyslot = get_random_string(3) - key = "{{{}}}:{}".format(keyslot, get_random_string(3)) # to get the same slot - value = get_random_string(5) - transaction = Transaction() - transaction.info() - transaction.select(1) - transaction.set(key, value) - transaction.get(key) - transaction.select(0) - transaction.get(key) - expected = transaction_test(transaction, keyslot) - result = await redis_client.exec(transaction) - assert isinstance(result, list) - assert isinstance(result[0], str) - assert "# Memory" in result[0] - assert result[1:6] == [OK, OK, value, OK, None] - assert result[6:] == expected - def test_transaction_clear(self): transaction = Transaction() transaction.info()