@@ -54,32 +54,28 @@ def mock_request(*args, **kwargs):
5454 assert mock_sleep .call_count == 2
5555
5656 def test_retries_on_429_rate_limit (self , sync_http_client , retry_config , monkeypatch ):
57- """Test that 429 errors trigger retry."""
57+ """Test that 429 errors do NOT trigger retry (consistent with workos-node) ."""
5858 call_count = 0
5959
6060 def mock_request (* args , ** kwargs ):
6161 nonlocal call_count
6262 call_count += 1
63- if call_count < 2 :
64- return httpx .Response (
65- status_code = 429 ,
66- headers = {"Retry-After" : "0.1" },
67- json = {"error" : "Rate limit exceeded" }
68- )
69- return httpx .Response (status_code = 200 , json = {"success" : True })
63+ return httpx .Response (
64+ status_code = 429 ,
65+ headers = {"Retry-After" : "0.1" },
66+ json = {"error" : "Rate limit exceeded" }
67+ )
7068
7169 monkeypatch .setattr (sync_http_client ._client , "request" , MagicMock (side_effect = mock_request ))
7270
73- with patch ( "time.sleep" ) as mock_sleep :
74- response = sync_http_client .request ("test/path" , retry_config = retry_config )
71+ with pytest . raises ( BadRequestException ) :
72+ sync_http_client .request ("test/path" , retry_config = retry_config )
7573
76- assert call_count == 2
77- assert response == {"success" : True }
78- # Verify Retry-After header was respected
79- mock_sleep .assert_called_once_with (0.1 )
74+ # Should only be called once (no retries on 429)
75+ assert call_count == 1
8076
8177 def test_no_retry_on_400_error (self , sync_http_client , monkeypatch ):
82- """Test that 4xx errors (except 429) don't retry (no retry_config passed)."""
78+ """Test that 4xx errors don't retry (no retry_config passed)."""
8379 call_count = 0
8480
8581 def mock_request (* args , ** kwargs ):
@@ -345,33 +341,29 @@ async def mock_request(*args, **kwargs):
345341
346342 @pytest .mark .asyncio
347343 async def test_retries_on_429_rate_limit (self , async_http_client , retry_config , monkeypatch ):
348- """Test that 429 errors trigger retry."""
344+ """Test that 429 errors do NOT trigger retry (consistent with workos-node) ."""
349345 call_count = 0
350346
351347 async def mock_request (* args , ** kwargs ):
352348 nonlocal call_count
353349 call_count += 1
354- if call_count < 2 :
355- return httpx .Response (
356- status_code = 429 ,
357- headers = {"Retry-After" : "0.1" },
358- json = {"error" : "Rate limit exceeded" }
359- )
360- return httpx .Response (status_code = 200 , json = {"success" : True })
350+ return httpx .Response (
351+ status_code = 429 ,
352+ headers = {"Retry-After" : "0.1" },
353+ json = {"error" : "Rate limit exceeded" }
354+ )
361355
362356 monkeypatch .setattr (async_http_client ._client , "request" , AsyncMock (side_effect = mock_request ))
363357
364- with patch ( "asyncio.sleep" ) as mock_sleep :
365- response = await async_http_client .request ("test/path" , retry_config = retry_config )
358+ with pytest . raises ( BadRequestException ) :
359+ await async_http_client .request ("test/path" , retry_config = retry_config )
366360
367- assert call_count == 2
368- assert response == {"success" : True }
369- # Verify Retry-After header was respected
370- mock_sleep .assert_called_once_with (0.1 )
361+ # Should only be called once (no retries on 429)
362+ assert call_count == 1
371363
372364 @pytest .mark .asyncio
373365 async def test_no_retry_on_400_error (self , async_http_client , monkeypatch ):
374- """Test that 4xx errors (except 429) don't retry (no retry_config passed)."""
366+ """Test that 4xx errors don't retry (no retry_config passed)."""
375367 call_count = 0
376368
377369 async def mock_request (* args , ** kwargs ):
0 commit comments