2626
2727
2828@pytest .fixture
29- def mock_time ():
30- with unittest .mock .patch .object (strands .event_loop .event_loop , "time" ) as mock :
29+ def mock_sleep ():
30+ with unittest .mock .patch .object (
31+ strands .event_loop .event_loop .asyncio , "sleep" , new_callable = unittest .mock .AsyncMock
32+ ) as mock :
3133 yield mock
3234
3335
@@ -186,7 +188,7 @@ async def test_event_loop_cycle_text_response(
186188
187189@pytest .mark .asyncio
188190async def test_event_loop_cycle_text_response_throttling (
189- mock_time ,
191+ mock_sleep ,
190192 agent ,
191193 model ,
192194 agenerator ,
@@ -215,12 +217,12 @@ async def test_event_loop_cycle_text_response_throttling(
215217
216218 assert tru_stop_reason == exp_stop_reason and tru_message == exp_message and tru_request_state == exp_request_state
217219 # Verify that sleep was called once with the initial delay
218- mock_time . sleep .assert_called_once ()
220+ mock_sleep .assert_called_once ()
219221
220222
221223@pytest .mark .asyncio
222224async def test_event_loop_cycle_exponential_backoff (
223- mock_time ,
225+ mock_sleep ,
224226 agent ,
225227 model ,
226228 agenerator ,
@@ -254,13 +256,13 @@ async def test_event_loop_cycle_exponential_backoff(
254256
255257 # Verify that sleep was called with increasing delays
256258 # Initial delay is 4, then 8, then 16
257- assert mock_time . sleep .call_count == 3
258- assert mock_time . sleep .call_args_list == [call (4 ), call (8 ), call (16 )]
259+ assert mock_sleep .call_count == 3
260+ assert mock_sleep .call_args_list == [call (4 ), call (8 ), call (16 )]
259261
260262
261263@pytest .mark .asyncio
262264async def test_event_loop_cycle_text_response_throttling_exceeded (
263- mock_time ,
265+ mock_sleep ,
264266 agent ,
265267 model ,
266268 alist ,
@@ -281,7 +283,7 @@ async def test_event_loop_cycle_text_response_throttling_exceeded(
281283 )
282284 await alist (stream )
283285
284- mock_time . sleep .assert_has_calls (
286+ mock_sleep .assert_has_calls (
285287 [
286288 call (4 ),
287289 call (8 ),
@@ -687,7 +689,7 @@ async def test_event_loop_tracing_with_throttling_exception(
687689 ]
688690
689691 # Mock the time.sleep function to speed up the test
690- with patch ("strands.event_loop.event_loop.time .sleep" ):
692+ with patch ("strands.event_loop.event_loop.asyncio .sleep" , new_callable = unittest . mock . AsyncMock ):
691693 stream = strands .event_loop .event_loop .event_loop_cycle (
692694 agent = agent ,
693695 invocation_state = {},
@@ -816,7 +818,7 @@ async def test_prepare_next_cycle_in_tool_execution(agent, model, tool_stream, a
816818
817819
818820@pytest .mark .asyncio
819- async def test_event_loop_cycle_exception_model_hooks (mock_time , agent , model , agenerator , alist , hook_provider ):
821+ async def test_event_loop_cycle_exception_model_hooks (mock_sleep , agent , model , agenerator , alist , hook_provider ):
820822 """Test that model hooks are correctly emitted even when throttled."""
821823 # Set up the model to raise throttling exceptions multiple times before succeeding
822824 exception = ModelThrottledException ("ThrottlingException | ConverseStream" )
0 commit comments