@@ -24,11 +24,16 @@ async def run(self, id: int) -> None:
2424 service = "MaxConcurrentTestService" ,
2525 )
2626
27- await nexus_client .execute_operation (
28- "op" ,
29- id ,
30- schedule_to_close_timeout = timedelta (seconds = 30 ),
31- )
27+ try :
28+ await nexus_client .execute_operation (
29+ "op" ,
30+ id ,
31+ schedule_to_close_timeout = timedelta (seconds = 30 ),
32+ )
33+ except Exception :
34+ # Expected for operations that can't get a slot or timeout
35+ # This prevents the workflow from hanging when Nexus operations fail
36+ pass
3237
3338
3439@pytest .mark .parametrize (
@@ -76,24 +81,35 @@ async def op(
7681 for i in range (num_nexus_operations )
7782 ]
7883
79- # Allow time for expected operations to start
80- deadline = asyncio .get_event_loop ().time () + 20.0
84+ # Wait for expected operations to start
85+ deadline = asyncio .get_event_loop ().time () + 10.0 # Reasonable timeout
8186 while len (ids ) < expected_num_executed :
8287 if asyncio .get_event_loop ().time () > deadline :
8388 break
84- await asyncio .sleep (0.1 )
89+ await asyncio .sleep (0.05 ) # Check frequently
8590
86- # No more should arrive
87- await asyncio .sleep (0.1 )
91+ # Brief wait to ensure no more operations slip through
92+ await asyncio .sleep (0.2 )
8893
94+ # Now release operations to let them complete
8995 event .set ()
9096
91- assert (
92- len (ids ) == expected_num_executed
93- ), f"Expected { expected_num_executed } operations, got { len (ids )} "
97+ # Verify the count
98+ assert len (ids ) == expected_num_executed , (
99+ f"Expected { expected_num_executed } operations, got { len (ids )} "
100+ )
94101 assert len (set (ids )) == len (ids ), "Duplicate operation IDs detected"
95102
103+ # Clean up: cancel remaining tasks and wait for them to finish
96104 for task in tasks :
97105 if not task .done ():
98106 task .cancel ()
99- await asyncio .gather (* tasks , return_exceptions = True )
107+
108+ # Use a short timeout to avoid hanging on cleanup
109+ try :
110+ await asyncio .wait_for (
111+ asyncio .gather (* tasks , return_exceptions = True ), timeout = 2.0
112+ )
113+ except asyncio .TimeoutError :
114+ # If cleanup times out, that's OK - we're done with the test
115+ pass
0 commit comments