@@ -561,6 +561,51 @@ def test_drain_is_non_blocking(self, http_client):
561561 assert elapsed < 1.0
562562
563563
564+ class TestInit :
565+ """Test initialization behavior."""
566+
567+ def test_missing_zmq_context_raises (self ):
568+ """HTTPEndpointClient raises ValueError without zmq_context."""
569+ config = HTTPClientConfig (
570+ endpoint_urls = ["http://localhost:8080/v1/chat/completions" ],
571+ num_workers = 1 ,
572+ max_connections = 10 ,
573+ warmup_connections = 0 ,
574+ )
575+ with pytest .raises (ValueError , match = "zmq_context is required" ):
576+ HTTPEndpointClient (config )
577+
578+ def test_external_loop_used (self , mock_http_echo_server ):
579+ """HTTPEndpointClient uses provided external loop."""
580+ from inference_endpoint .async_utils .loop_manager import LoopManager
581+
582+ manager = LoopManager ()
583+ loop = manager .create_loop (
584+ name = "test-external-loop" ,
585+ backend = "uvloop" ,
586+ task_factory_mode = "eager" ,
587+ )
588+ try :
589+ with ManagedZMQContext .scoped () as zmq_ctx :
590+ client = HTTPEndpointClient (
591+ HTTPClientConfig (
592+ endpoint_urls = [
593+ f"{ mock_http_echo_server .url } /v1/chat/completions"
594+ ],
595+ num_workers = 1 ,
596+ max_connections = 10 ,
597+ warmup_connections = 0 ,
598+ ),
599+ loop = loop ,
600+ zmq_context = zmq_ctx ,
601+ )
602+ assert client .loop is loop
603+ assert not client ._owns_loop # Didn't create it, doesn't own it
604+ client .shutdown ()
605+ finally :
606+ manager .stop_loop ("test-external-loop" )
607+
608+
564609class TestShutdown :
565610 """Test shutdown behavior."""
566611
@@ -583,3 +628,13 @@ def test_issue_after_shutdown_drops(self, mock_http_echo_server):
583628 )
584629 client .shutdown ()
585630 client .issue (_make_query ("post-shutdown" ))
631+
632+ def test_shutdown_logs_dropped_requests (self , mock_http_echo_server ):
633+ """Shutdown logs count of dropped requests when > 0."""
634+ with ManagedZMQContext .scoped () as zmq_ctx :
635+ client = _create_client (
636+ f"{ mock_http_echo_server .url } /v1/chat/completions" ,
637+ zmq_context = zmq_ctx ,
638+ )
639+ client ._dropped_requests = 3
640+ client .shutdown ()
0 commit comments