@@ -24,17 +24,19 @@ def mock_telemetry_client():
2424 session_id = str (uuid .uuid4 ())
2525 auth_provider = AccessTokenAuthProvider ("test-token" )
2626 executor = MagicMock ()
27- mock_http_client = MagicMock ()
28-
29- return TelemetryClient (
30- telemetry_enabled = True ,
31- session_id_hex = session_id ,
32- auth_provider = auth_provider ,
33- host_url = "test-host.com" ,
34- executor = executor ,
35- batch_size = TelemetryClientFactory .DEFAULT_BATCH_SIZE ,
36- http_client = mock_http_client ,
37- )
27+ client_context = MagicMock ()
28+
29+ # Patch the _setup_pool_manager method to avoid SSL file loading
30+ with patch ('databricks.sql.common.unified_http_client.UnifiedHttpClient._setup_pool_manager' ):
31+ return TelemetryClient (
32+ telemetry_enabled = True ,
33+ session_id_hex = session_id ,
34+ auth_provider = auth_provider ,
35+ host_url = "test-host.com" ,
36+ executor = executor ,
37+ batch_size = TelemetryClientFactory .DEFAULT_BATCH_SIZE ,
38+ client_context = client_context ,
39+ )
3840
3941
4042class TestNoopTelemetryClient :
@@ -216,41 +218,42 @@ def test_client_lifecycle_flow(self):
216218 """Test complete client lifecycle: initialize -> use -> close."""
217219 session_id_hex = "test-session"
218220 auth_provider = AccessTokenAuthProvider ("token" )
219- mock_http_client = MagicMock ()
221+ client_context = MagicMock ()
220222
221223 # Initialize enabled client
222- TelemetryClientFactory .initialize_telemetry_client (
223- telemetry_enabled = True ,
224- session_id_hex = session_id_hex ,
225- auth_provider = auth_provider ,
226- host_url = "test-host.com" ,
227- batch_size = TelemetryClientFactory .DEFAULT_BATCH_SIZE ,
228- http_client = mock_http_client ,
229- )
224+ with patch ('databricks.sql.common.unified_http_client.UnifiedHttpClient._setup_pool_manager' ):
225+ TelemetryClientFactory .initialize_telemetry_client (
226+ telemetry_enabled = True ,
227+ session_id_hex = session_id_hex ,
228+ auth_provider = auth_provider ,
229+ host_url = "test-host.com" ,
230+ batch_size = TelemetryClientFactory .DEFAULT_BATCH_SIZE ,
231+ client_context = client_context ,
232+ )
230233
231- client = TelemetryClientFactory .get_telemetry_client (session_id_hex )
232- assert isinstance (client , TelemetryClient )
233- assert client ._session_id_hex == session_id_hex
234+ client = TelemetryClientFactory .get_telemetry_client (session_id_hex )
235+ assert isinstance (client , TelemetryClient )
236+ assert client ._session_id_hex == session_id_hex
234237
235- # Close client
236- with patch .object (client , "close" ) as mock_close :
237- TelemetryClientFactory .close (session_id_hex )
238- mock_close .assert_called_once ()
238+ # Close client
239+ with patch .object (client , "close" ) as mock_close :
240+ TelemetryClientFactory .close (session_id_hex )
241+ mock_close .assert_called_once ()
239242
240- # Should get NoopTelemetryClient after close
243+ # Should get NoopTelemetryClient after close
241244
242245 def test_disabled_telemetry_creates_noop_client (self ):
243246 """Test that disabled telemetry creates NoopTelemetryClient."""
244247 session_id_hex = "test-session"
245- mock_http_client = MagicMock ()
248+ client_context = MagicMock ()
246249
247250 TelemetryClientFactory .initialize_telemetry_client (
248251 telemetry_enabled = False ,
249252 session_id_hex = session_id_hex ,
250253 auth_provider = None ,
251254 host_url = "test-host.com" ,
252255 batch_size = TelemetryClientFactory .DEFAULT_BATCH_SIZE ,
253- http_client = mock_http_client ,
256+ client_context = client_context ,
254257 )
255258
256259 client = TelemetryClientFactory .get_telemetry_client (session_id_hex )
@@ -259,7 +262,7 @@ def test_disabled_telemetry_creates_noop_client(self):
259262 def test_factory_error_handling (self ):
260263 """Test that factory errors fall back to NoopTelemetryClient."""
261264 session_id = "test-session"
262- mock_http_client = MagicMock ()
265+ client_context = MagicMock ()
263266
264267 # Simulate initialization error
265268 with patch (
@@ -272,7 +275,7 @@ def test_factory_error_handling(self):
272275 auth_provider = AccessTokenAuthProvider ("token" ),
273276 host_url = "test-host.com" ,
274277 batch_size = TelemetryClientFactory .DEFAULT_BATCH_SIZE ,
275- http_client = mock_http_client ,
278+ client_context = client_context ,
276279 )
277280
278281 # Should fall back to NoopTelemetryClient
@@ -283,31 +286,32 @@ def test_factory_shutdown_flow(self):
283286 """Test factory shutdown when last client is removed."""
284287 session1 = "session-1"
285288 session2 = "session-2"
286- mock_http_client = MagicMock ()
289+ client_context = MagicMock ()
287290
288291 # Initialize multiple clients
289- for session in [session1 , session2 ]:
290- TelemetryClientFactory .initialize_telemetry_client (
291- telemetry_enabled = True ,
292- session_id_hex = session ,
293- auth_provider = AccessTokenAuthProvider ("token" ),
294- host_url = "test-host.com" ,
295- batch_size = TelemetryClientFactory .DEFAULT_BATCH_SIZE ,
296- http_client = mock_http_client ,
297- )
298-
299- # Factory should be initialized
300- assert TelemetryClientFactory ._initialized is True
301- assert TelemetryClientFactory ._executor is not None
302-
303- # Close first client - factory should stay initialized
304- TelemetryClientFactory .close (session1 )
305- assert TelemetryClientFactory ._initialized is True
306-
307- # Close second client - factory should shut down
308- TelemetryClientFactory .close (session2 )
309- assert TelemetryClientFactory ._initialized is False
310- assert TelemetryClientFactory ._executor is None
292+ with patch ('databricks.sql.common.unified_http_client.UnifiedHttpClient._setup_pool_manager' ):
293+ for session in [session1 , session2 ]:
294+ TelemetryClientFactory .initialize_telemetry_client (
295+ telemetry_enabled = True ,
296+ session_id_hex = session ,
297+ auth_provider = AccessTokenAuthProvider ("token" ),
298+ host_url = "test-host.com" ,
299+ batch_size = TelemetryClientFactory .DEFAULT_BATCH_SIZE ,
300+ client_context = client_context ,
301+ )
302+
303+ # Factory should be initialized
304+ assert TelemetryClientFactory ._initialized is True
305+ assert TelemetryClientFactory ._executor is not None
306+
307+ # Close first client - factory should stay initialized
308+ TelemetryClientFactory .close (session1 )
309+ assert TelemetryClientFactory ._initialized is True
310+
311+ # Close second client - factory should shut down
312+ TelemetryClientFactory .close (session2 )
313+ assert TelemetryClientFactory ._initialized is False
314+ assert TelemetryClientFactory ._executor is None
311315
312316 @patch (
313317 "databricks.sql.telemetry.telemetry_client.TelemetryClient.export_failure_log"
0 commit comments