fix(test): use _original_sleep in slow executor steps to fix flaky timeout test
The test-infrastructure patches asyncio.sleep with a 10 ms cap to speed up retry waits. The two slow-executor Behave step definitions used asyncio.sleep(10) as the "slow" coroutine, which was silently capped to 10 ms — the same duration as the 0.01 s executor timeout — creating a race condition that caused the "Executor times out via thread pool path" and "Executor times out via run_coroutine_threadsafe path" scenarios to fail intermittently. Fix: use asyncio._original_sleep (falling back to asyncio.sleep when the patch is absent) with a 0.5 s delay, which is 50× longer than the timeout and guarantees the timeout always fires before the coroutine completes.
This commit is contained in:
@@ -709,7 +709,10 @@ def step_prepare_slow_executor_bg_loop(context):
|
||||
context.graph.state_manager.update_state = MagicMock()
|
||||
|
||||
async def slow_execute(state):
|
||||
await asyncio.sleep(10)
|
||||
# Use the original (un-patched) asyncio.sleep so the test-infrastructure
|
||||
# 10 ms sleep cap does not race with the 0.01 s executor timeout.
|
||||
_real_sleep = getattr(asyncio, "_original_sleep", asyncio.sleep)
|
||||
await _real_sleep(0.5)
|
||||
return {"messages": ["never"]}
|
||||
|
||||
context.graph.nodes["worker"].execute = slow_execute
|
||||
@@ -745,7 +748,10 @@ def step_prepare_slow_executor_tp(context):
|
||||
context.graph.state_manager.update_state = MagicMock()
|
||||
|
||||
async def slow_execute(state):
|
||||
await asyncio.sleep(10)
|
||||
# Use the original (un-patched) asyncio.sleep so the test-infrastructure
|
||||
# 10 ms sleep cap does not race with the 0.01 s executor timeout.
|
||||
_real_sleep = getattr(asyncio, "_original_sleep", asyncio.sleep)
|
||||
await _real_sleep(0.5)
|
||||
return {"messages": ["never"]}
|
||||
|
||||
context.graph.nodes["worker"].execute = slow_execute
|
||||
|
||||
Reference in New Issue
Block a user