@@ -1006,6 +1006,67 @@ def test_send_pubsub_ping_message(self, r):
10061006 )
10071007
10081008
1009+ @pytest .mark .onlynoncluster
1010+ class TestPubSubHealthCheckResponse :
1011+ """Tests for health check response validation with different decode_responses settings"""
1012+
1013+ def test_is_health_check_response_decode_false_list_format (self , r ):
1014+ """Test is_health_check_response recognizes list format with decode_responses=False"""
1015+ p = r .pubsub ()
1016+ # List format: [b"pong", b"redis-py-health-check"]
1017+ assert p .is_health_check_response ([b"pong" , b"redis-py-health-check" ])
1018+
1019+ def test_is_health_check_response_decode_false_bytes_format (self , r ):
1020+ """Test is_health_check_response recognizes bytes format with decode_responses=False"""
1021+ p = r .pubsub ()
1022+ # Bytes format: b"redis-py-health-check"
1023+ assert p .is_health_check_response (b"redis-py-health-check" )
1024+
1025+ def test_is_health_check_response_decode_false_rejects_string (self , r ):
1026+ """Test is_health_check_response rejects string format with decode_responses=False"""
1027+ p = r .pubsub ()
1028+ # String format should NOT be recognized when decode_responses=False
1029+ assert not p .is_health_check_response ("redis-py-health-check" )
1030+
1031+ def test_is_health_check_response_decode_true_list_format (self , request ):
1032+ """Test is_health_check_response recognizes list format with decode_responses=True"""
1033+ r = _get_client (redis .Redis , request , decode_responses = True )
1034+ p = r .pubsub ()
1035+ # List format: ["pong", "redis-py-health-check"]
1036+ assert p .is_health_check_response (["pong" , "redis-py-health-check" ])
1037+
1038+ def test_is_health_check_response_decode_true_string_format (self , request ):
1039+ """Test is_health_check_response recognizes string format with decode_responses=True"""
1040+ r = _get_client (redis .Redis , request , decode_responses = True )
1041+ p = r .pubsub ()
1042+ # String format: "redis-py-health-check" (THE FIX!)
1043+ assert p .is_health_check_response ("redis-py-health-check" )
1044+
1045+ def test_is_health_check_response_decode_true_rejects_bytes (self , request ):
1046+ """Test is_health_check_response rejects bytes format with decode_responses=True"""
1047+ r = _get_client (redis .Redis , request , decode_responses = True )
1048+ p = r .pubsub ()
1049+ # Bytes format should NOT be recognized when decode_responses=True
1050+ assert not p .is_health_check_response (b"redis-py-health-check" )
1051+
1052+ def test_is_health_check_response_decode_true_rejects_invalid (self , request ):
1053+ """Test is_health_check_response rejects invalid responses with decode_responses=True"""
1054+ r = _get_client (redis .Redis , request , decode_responses = True )
1055+ p = r .pubsub ()
1056+ # Invalid responses should be rejected
1057+ assert not p .is_health_check_response ("invalid-response" )
1058+ assert not p .is_health_check_response (["pong" , "invalid-response" ])
1059+ assert not p .is_health_check_response (None )
1060+
1061+ def test_is_health_check_response_decode_false_rejects_invalid (self , r ):
1062+ """Test is_health_check_response rejects invalid responses with decode_responses=False"""
1063+ p = r .pubsub ()
1064+ # Invalid responses should be rejected
1065+ assert not p .is_health_check_response (b"invalid-response" )
1066+ assert not p .is_health_check_response ([b"pong" , b"invalid-response" ])
1067+ assert not p .is_health_check_response (None )
1068+
1069+
10091070@pytest .mark .onlynoncluster
10101071class TestPubSubConnectionKilled :
10111072 @skip_if_server_version_lt ("3.0.0" )
0 commit comments