@@ -498,4 +498,69 @@ def test_global_exception_hook(self, mock_handle_exception, telemetry_system_res
498498 test_exception = ValueError ("Test exception" )
499499 TelemetryClientFactory ._handle_unhandled_exception (type (test_exception ), test_exception , None )
500500
501- mock_handle_exception .assert_called_once_with (type (test_exception ), test_exception , None )
501+ mock_handle_exception .assert_called_once_with (type (test_exception ), test_exception , None )
502+
503+ @patch ("requests.post" )
504+ @patch ("databricks.sql.telemetry.telemetry_client.TelemetryHelper.get_driver_system_configuration" )
505+ @patch ("databricks.sql.telemetry.telemetry_client.TelemetryFrontendLog" )
506+ @patch ("databricks.sql.telemetry.telemetry_client.DriverErrorInfo" )
507+ @patch ("databricks.sql.telemetry.telemetry_client.DriverConnectionParameters" )
508+ @patch ("databricks.sql.telemetry.telemetry_client.uuid.uuid4" )
509+ @patch ("databricks.sql.telemetry.telemetry_client.time.time" )
510+ def test_send_connection_error_telemetry (
511+ self ,
512+ mock_time ,
513+ mock_uuid4 ,
514+ mock_driver_connection_params ,
515+ mock_driver_error_info ,
516+ mock_frontend_log ,
517+ mock_get_driver_config ,
518+ mock_post ,
519+ telemetry_system_reset
520+ ):
521+ """Test connection error telemetry functionality."""
522+ # Setup mocks
523+ mock_time .return_value = 1000
524+ mock_uuid4 .return_value = "test-uuid"
525+ mock_get_driver_config .return_value = MagicMock ()
526+ mock_driver_connection_params .return_value = MagicMock ()
527+ mock_driver_error_info .return_value = MagicMock ()
528+
529+ mock_frontend_log_instance = MagicMock ()
530+ mock_frontend_log_instance .to_json .return_value = '{"test": "data"}'
531+ mock_frontend_log .return_value = mock_frontend_log_instance
532+
533+ mock_response = MagicMock ()
534+ mock_response .status_code = 200
535+ mock_post .return_value = mock_response
536+
537+ # Test successful call
538+ TelemetryClientFactory .send_connection_error_telemetry (
539+ error_name = "ConnectionError" ,
540+ error_message = "Failed to connect" ,
541+ host_url = "test.databricks.com" ,
542+ http_path = "/sql/1.0/endpoints/test" ,
543+ port = 443 ,
544+ user_agent = "TestAgent"
545+ )
546+
547+ # Verify requests.post was called correctly
548+ mock_post .assert_called_once ()
549+ args , kwargs = mock_post .call_args
550+ assert args [0 ] == "https://test.databricks.com/telemetry-unauth"
551+ assert kwargs ["headers" ]["Accept" ] == "application/json"
552+ assert kwargs ["timeout" ] == 5
553+
554+ # Test that exceptions don't break the function
555+ mock_post .reset_mock ()
556+ mock_post .side_effect = Exception ("Network error" )
557+
558+ # Should not raise exception
559+ TelemetryClientFactory .send_connection_error_telemetry (
560+ error_name = "AuthenticationError" ,
561+ error_message = "Auth failed" ,
562+ host_url = "test.databricks.com" ,
563+ http_path = "/sql/1.0/endpoints/test"
564+ )
565+
566+ mock_post .assert_called_once ()
0 commit comments