@@ -198,7 +198,7 @@ def test_export_event(self, telemetry_client_setup):
198
198
client ._flush .assert_called_once ()
199
199
assert len (client ._events_batch ) == 10
200
200
201
- @patch ("requests.post" )
201
+ @patch ("requests.Session. post" )
202
202
def test_send_telemetry_authenticated (self , mock_post , telemetry_client_setup ):
203
203
"""Test sending telemetry to the server with authentication."""
204
204
client = telemetry_client_setup ["client" ]
@@ -212,12 +212,12 @@ def test_send_telemetry_authenticated(self, mock_post, telemetry_client_setup):
212
212
213
213
executor .submit .assert_called_once ()
214
214
args , kwargs = executor .submit .call_args
215
- assert args [0 ] == requests .post
215
+ assert args [0 ] == client . _session .post
216
216
assert kwargs ["timeout" ] == 10
217
217
assert "Authorization" in kwargs ["headers" ]
218
218
assert kwargs ["headers" ]["Authorization" ] == "Bearer test-token"
219
219
220
- @patch ("requests.post" )
220
+ @patch ("requests.Session. post" )
221
221
def test_send_telemetry_unauthenticated (self , mock_post , telemetry_client_setup ):
222
222
"""Test sending telemetry to the server without authentication."""
223
223
host_url = telemetry_client_setup ["host_url" ]
@@ -239,7 +239,7 @@ def test_send_telemetry_unauthenticated(self, mock_post, telemetry_client_setup)
239
239
240
240
executor .submit .assert_called_once ()
241
241
args , kwargs = executor .submit .call_args
242
- assert args [0 ] == requests .post
242
+ assert args [0 ] == unauthenticated_client . _session .post
243
243
assert kwargs ["timeout" ] == 10
244
244
assert "Authorization" not in kwargs ["headers" ] # No auth header
245
245
assert kwargs ["headers" ]["Accept" ] == "application/json"
@@ -331,6 +331,34 @@ class TestBaseClient(BaseTelemetryClient):
331
331
with pytest .raises (TypeError ):
332
332
TestBaseClient () # Can't instantiate abstract class
333
333
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
+
334
362
335
363
class TestTelemetryHelper :
336
364
"""Tests for the TelemetryHelper class."""
0 commit comments