@@ -759,6 +759,27 @@ def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> Non
759759
760760 assert _get_open_connections (self .client ) == 0
761761
762+ @pytest .mark .parametrize ("failures_before_success" , [0 , 2 , 4 ])
763+ @mock .patch ("runloop_api_client._base_client.BaseClient._calculate_retry_timeout" , _low_retry_timeout )
764+ @pytest .mark .respx (base_url = base_url )
765+ def test_retries_taken (self , client : Runloop , failures_before_success : int , respx_mock : MockRouter ) -> None :
766+ client = client .with_options (max_retries = 4 )
767+
768+ nb_retries = 0
769+
770+ def retry_handler (_request : httpx .Request ) -> httpx .Response :
771+ nonlocal nb_retries
772+ if nb_retries < failures_before_success :
773+ nb_retries += 1
774+ return httpx .Response (500 )
775+ return httpx .Response (200 )
776+
777+ respx_mock .post ("/v1/devboxes" ).mock (side_effect = retry_handler )
778+
779+ response = client .devboxes .with_raw_response .create ()
780+
781+ assert response .retries_taken == failures_before_success
782+
762783
763784class TestAsyncRunloop :
764785 client = AsyncRunloop (base_url = base_url , bearer_token = bearer_token , _strict_response_validation = True )
@@ -1473,3 +1494,27 @@ async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter)
14731494 )
14741495
14751496 assert _get_open_connections (self .client ) == 0
1497+
1498+ @pytest .mark .parametrize ("failures_before_success" , [0 , 2 , 4 ])
1499+ @mock .patch ("runloop_api_client._base_client.BaseClient._calculate_retry_timeout" , _low_retry_timeout )
1500+ @pytest .mark .respx (base_url = base_url )
1501+ @pytest .mark .asyncio
1502+ async def test_retries_taken (
1503+ self , async_client : AsyncRunloop , failures_before_success : int , respx_mock : MockRouter
1504+ ) -> None :
1505+ client = async_client .with_options (max_retries = 4 )
1506+
1507+ nb_retries = 0
1508+
1509+ def retry_handler (_request : httpx .Request ) -> httpx .Response :
1510+ nonlocal nb_retries
1511+ if nb_retries < failures_before_success :
1512+ nb_retries += 1
1513+ return httpx .Response (500 )
1514+ return httpx .Response (200 )
1515+
1516+ respx_mock .post ("/v1/devboxes" ).mock (side_effect = retry_handler )
1517+
1518+ response = await client .devboxes .with_raw_response .create ()
1519+
1520+ assert response .retries_taken == failures_before_success
0 commit comments