@@ -198,7 +198,7 @@ def test_export_event(self, telemetry_client_setup):
198198 client ._flush .assert_called_once ()
199199 assert len (client ._events_batch ) == 10
200200
201- @patch ("requests.post" )
201+ @patch ("requests.Session. post" )
202202 def test_send_telemetry_authenticated (self , mock_post , telemetry_client_setup ):
203203 """Test sending telemetry to the server with authentication."""
204204 client = telemetry_client_setup ["client" ]
@@ -212,12 +212,12 @@ def test_send_telemetry_authenticated(self, mock_post, telemetry_client_setup):
212212
213213 executor .submit .assert_called_once ()
214214 args , kwargs = executor .submit .call_args
215- assert args [0 ] == requests .post
215+ assert args [0 ] == client . _session .post
216216 assert kwargs ["timeout" ] == 10
217217 assert "Authorization" in kwargs ["headers" ]
218218 assert kwargs ["headers" ]["Authorization" ] == "Bearer test-token"
219219
220- @patch ("requests.post" )
220+ @patch ("requests.Session. post" )
221221 def test_send_telemetry_unauthenticated (self , mock_post , telemetry_client_setup ):
222222 """Test sending telemetry to the server without authentication."""
223223 host_url = telemetry_client_setup ["host_url" ]
@@ -239,7 +239,7 @@ def test_send_telemetry_unauthenticated(self, mock_post, telemetry_client_setup)
239239
240240 executor .submit .assert_called_once ()
241241 args , kwargs = executor .submit .call_args
242- assert args [0 ] == requests .post
242+ assert args [0 ] == unauthenticated_client . _session .post
243243 assert kwargs ["timeout" ] == 10
244244 assert "Authorization" not in kwargs ["headers" ] # No auth header
245245 assert kwargs ["headers" ]["Accept" ] == "application/json"
@@ -331,6 +331,34 @@ class TestBaseClient(BaseTelemetryClient):
331331 with pytest .raises (TypeError ):
332332 TestBaseClient () # Can't instantiate abstract class
333333
334+ def test_telemetry_http_adapter_retry_policy (self , telemetry_client_setup ):
335+ """Test that TelemetryHTTPAdapter properly configures DatabricksRetryPolicy."""
336+ from databricks .sql .telemetry .telemetry_client import TelemetryHTTPAdapter
337+ from databricks .sql .auth .retry import DatabricksRetryPolicy , CommandType
338+
339+ client = telemetry_client_setup ["client" ]
340+
341+ # Verify that the session has the TelemetryHTTPAdapter mounted
342+ adapter = client ._session .adapters .get ("https://" )
343+ assert isinstance (adapter , TelemetryHTTPAdapter )
344+ assert isinstance (adapter .max_retries , DatabricksRetryPolicy )
345+
346+ # Verify that the retry policy has the correct configuration
347+ retry_policy = adapter .max_retries
348+ assert retry_policy .delay_min == client .TELEMETRY_RETRY_DELAY_MIN
349+ assert retry_policy .delay_max == client .TELEMETRY_RETRY_DELAY_MAX
350+ assert retry_policy .stop_after_attempts_count == client .TELEMETRY_RETRY_STOP_AFTER_ATTEMPTS_COUNT
351+ assert retry_policy .stop_after_attempts_duration == client .TELEMETRY_RETRY_STOP_AFTER_ATTEMPTS_DURATION
352+
353+ # Test that the adapter's send method would properly configure the retry policy
354+ # by directly testing the logic that sets command_type and starts the timer
355+ if isinstance (adapter .max_retries , DatabricksRetryPolicy ):
356+ adapter .max_retries .command_type = CommandType .OTHER
357+ adapter .max_retries .start_retry_timer ()
358+
359+ # Verify that the retry policy was configured correctly
360+ assert retry_policy .command_type == CommandType .OTHER
361+
334362
335363class TestTelemetryHelper :
336364 """Tests for the TelemetryHelper class."""
0 commit comments