@@ -892,6 +892,67 @@ def test_send_pubsub_ping_message(self, r):
892892 )
893893
894894
895+ @pytest .mark .onlynoncluster
896+ class TestPubSubHealthCheckResponse :
897+ """Tests for health check response validation with different decode_responses settings"""
898+
899+ def test_is_health_check_response_decode_false_list_format (self , r ):
900+ """Test is_health_check_response recognizes list format with decode_responses=False"""
901+ p = r .pubsub ()
902+ # List format: [b"pong", b"redis-py-health-check"]
903+ assert p .is_health_check_response ([b"pong" , b"redis-py-health-check" ])
904+
905+ def test_is_health_check_response_decode_false_bytes_format (self , r ):
906+ """Test is_health_check_response recognizes bytes format with decode_responses=False"""
907+ p = r .pubsub ()
908+ # Bytes format: b"redis-py-health-check"
909+ assert p .is_health_check_response (b"redis-py-health-check" )
910+
911+ def test_is_health_check_response_decode_false_rejects_string (self , r ):
912+ """Test is_health_check_response rejects string format with decode_responses=False"""
913+ p = r .pubsub ()
914+ # String format should NOT be recognized when decode_responses=False
915+ assert not p .is_health_check_response ("redis-py-health-check" )
916+
917+ def test_is_health_check_response_decode_true_list_format (self , request ):
918+ """Test is_health_check_response recognizes list format with decode_responses=True"""
919+ r = _get_client (redis .Redis , request , decode_responses = True )
920+ p = r .pubsub ()
921+ # List format: ["pong", "redis-py-health-check"]
922+ assert p .is_health_check_response (["pong" , "redis-py-health-check" ])
923+
924+ def test_is_health_check_response_decode_true_string_format (self , request ):
925+ """Test is_health_check_response recognizes string format with decode_responses=True"""
926+ r = _get_client (redis .Redis , request , decode_responses = True )
927+ p = r .pubsub ()
928+ # String format: "redis-py-health-check" (THE FIX!)
929+ assert p .is_health_check_response ("redis-py-health-check" )
930+
931+ def test_is_health_check_response_decode_true_rejects_bytes (self , request ):
932+ """Test is_health_check_response rejects bytes format with decode_responses=True"""
933+ r = _get_client (redis .Redis , request , decode_responses = True )
934+ p = r .pubsub ()
935+ # Bytes format should NOT be recognized when decode_responses=True
936+ assert not p .is_health_check_response (b"redis-py-health-check" )
937+
938+ def test_is_health_check_response_decode_true_rejects_invalid (self , request ):
939+ """Test is_health_check_response rejects invalid responses with decode_responses=True"""
940+ r = _get_client (redis .Redis , request , decode_responses = True )
941+ p = r .pubsub ()
942+ # Invalid responses should be rejected
943+ assert not p .is_health_check_response ("invalid-response" )
944+ assert not p .is_health_check_response (["pong" , "invalid-response" ])
945+ assert not p .is_health_check_response (None )
946+
947+ def test_is_health_check_response_decode_false_rejects_invalid (self , r ):
948+ """Test is_health_check_response rejects invalid responses with decode_responses=False"""
949+ p = r .pubsub ()
950+ # Invalid responses should be rejected
951+ assert not p .is_health_check_response (b"invalid-response" )
952+ assert not p .is_health_check_response ([b"pong" , b"invalid-response" ])
953+ assert not p .is_health_check_response (None )
954+
955+
895956@pytest .mark .onlynoncluster
896957class TestPubSubConnectionKilled :
897958 @skip_if_server_version_lt ("3.0.0" )
0 commit comments