@@ -382,6 +382,26 @@ def test_loadbalancer_handle_4xx_failure(self, client_same_priority):
382
382
# Assert that the final response status code was 400
383
383
assert response .status_code == 400
384
384
385
+ @pytest .mark .loadbalancer
386
+ def test_loadbalancer_loadbalancer_close (self , client_same_priority ):
387
+ client = client_same_priority
388
+
389
+ # Create a mock response for the transport
390
+ mock_response = httpx .Response (200 )
391
+
392
+ with patch ('httpx.Client.send' , return_value = mock_response ):
393
+ req = client ._build_request (create_final_request_options ())
394
+ response = client ._client ._transport .handle_request (req )
395
+
396
+ assert response .status_code == 200
397
+
398
+ # Assert that the transport is not closed, then close it, then assert that it was closed.
399
+ assert client ._client ._transport .is_closed is False
400
+
401
+ client ._client ._transport .close ()
402
+
403
+ assert client ._client ._transport .is_closed is True
404
+
385
405
# Asynchronous Tests
386
406
387
407
class TestAsynchronous :
@@ -591,3 +611,24 @@ async def test_async_loadbalancer_handle_4xx_failure(self, async_client_same_pri
591
611
592
612
# Assert that the final response status code was 400
593
613
assert response .status_code == 400
614
+
615
+ @pytest .mark .asyncio
616
+ @pytest .mark .async_loadbalancer
617
+ async def test_async_loadbalancer_close (self , async_client_same_priority ):
618
+ client = async_client_same_priority
619
+
620
+ # Create a mock response for the transport
621
+ mock_response = httpx .Response (200 )
622
+
623
+ with patch ('httpx.AsyncClient.send' , return_value = mock_response ):
624
+ req = client ._build_request (create_final_request_options ())
625
+ response = await client ._client ._transport .handle_async_request (req )
626
+
627
+ assert response .status_code == 200
628
+
629
+ # Assert that the transport is not closed, then close it, then assert that it was closed.
630
+ assert client ._client ._transport .is_closed is False
631
+
632
+ await client ._client ._transport .aclose ()
633
+
634
+ assert client ._client ._transport .is_closed is True
0 commit comments