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