@@ -1507,30 +1507,41 @@ async def test_normalizer_surfaces_lifecycle_failures_async(
15071507
15081508
15091509@pytest .mark .usefixtures ("patch_central_database" )
1510+ @pytest .mark .parametrize ("startup_delay_seconds" , [0.0 , 2.1 ])
15101511async def test_normalizer_surfaces_dispatch_timeout_and_cleans_up_without_replay_async (
15111512 * ,
15121513 sdk : Any ,
15131514 client : NonCallableMagicMock ,
1515+ startup_delay_seconds : float ,
15141516) -> None :
15151517 session = client .create_session .return_value
15161518 target = GitHubCopilotTarget (model_name = "gpt-5-mini" , response_timeout_seconds = 0.01 )
1519+ send_entered = asyncio .Event ()
1520+
1521+ async def start_async () -> None :
1522+ await asyncio .sleep (startup_delay_seconds )
1523+
1524+ client .start .side_effect = start_async
15171525
15181526 async def stall_send_async (* _args : Any , ** _kwargs : Any ) -> None :
1527+ send_entered .set ()
15191528 await asyncio .Event ().wait ()
15201529
15211530 session .send .side_effect = stall_send_async
15221531 session .send_and_wait .side_effect = partial (sdk .CopilotSession .send_and_wait , session )
1523- with pytest .raises (Exception , match = "Error sending prompt with conversation ID:" ) as exc_info :
1524- # A bare watchdog TimeoutError must not satisfy the normalizer-wrapped failure.
1525- await asyncio .wait_for (
1526- _send_normalized_async (target = target , original_value = "Reply exactly HELLO." ),
1527- timeout = 2.0 ,
1528- )
1529- assert isinstance (exc_info .value .__cause__ , TimeoutError )
1530- session .send .assert_awaited_once ()
1531- client .delete_session .assert_awaited_once_with ("sdk-session-id" )
1532- client .stop .assert_not_awaited ()
1533- await target .cleanup_target_async ()
1532+ send_task = asyncio .create_task (_send_normalized_async (target = target , original_value = "Reply exactly HELLO." ))
1533+ try :
1534+ await asyncio .wait_for (send_entered .wait (), timeout = 10.0 )
1535+ with pytest .raises (Exception , match = "Error sending prompt with conversation ID:" ) as exc_info :
1536+ # A bare watchdog TimeoutError must not satisfy the normalizer-wrapped failure.
1537+ await asyncio .wait_for (send_task , timeout = 10.0 )
1538+ assert isinstance (exc_info .value .__cause__ , TimeoutError )
1539+ session .send .assert_awaited_once ()
1540+ client .delete_session .assert_awaited_once_with ("sdk-session-id" )
1541+ client .stop .assert_not_awaited ()
1542+ finally :
1543+ await _cancel_tasks_async (send_task )
1544+ await target .cleanup_target_async ()
15341545 client .stop .assert_awaited_once ()
15351546
15361547
0 commit comments