Skip to content

Commit ea89611

Browse files
isaacbmillerampagentIsaac Miller
authored
fix(tests): deflake LocalInterpreter timeout tests (#10630)
Two tests used execution_timeout=0.1, which only has to cover one request/response round trip to the worker. On loaded CI runners that round trip occasionally exceeds 100ms, so the timeout fires on code that should return immediately (execute("if")) or before the host tool request arrives. Use a 1s timeout, exclude worker startup from the elapsed measurement, and block the host tool on an event instead of a short sleep so the test still fails if execute() waits for a blocked tool. Amp-Thread-ID: https://ampcode.com/threads/T-01a13070-310d-739a-abc1-9b4c33bffaa6 Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
1 parent d41d142 commit ea89611

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎tests/primitives/test_local_interpreter.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_guest_cannot_corrupt_interpreter_owned_globals_across_executions():
161161

162162

163163
def test_errors_are_recoverable_but_timeout_is_terminal():
164-
interpreter = dspy.LocalInterpreter(execution_timeout=0.1)
164+
interpreter = dspy.LocalInterpreter(execution_timeout=1)
165165
with pytest.raises(SyntaxError):
166166
interpreter.execute("if")
167167
with pytest.raises(CodeExecutionError, match="ZeroDivisionError"):
@@ -223,20 +223,23 @@ def echo(value):
223223

224224
def test_execution_timeout_does_not_wait_for_blocked_host_tool():
225225
tool_started = threading.Event()
226+
release_tool = threading.Event()
226227

227228
def blocked():
228229
tool_started.set()
229-
time.sleep(1)
230+
release_tool.wait(timeout=10)
230231
return 42
231232

232-
interpreter = dspy.LocalInterpreter(tools={"blocked": blocked}, execution_timeout=0.1)
233+
interpreter = dspy.LocalInterpreter(tools={"blocked": blocked}, execution_timeout=1)
234+
interpreter.start()
233235
started = time.monotonic()
234236
with pytest.raises(CodeInterpreterError, match="exceeded execution timeout"):
235237
interpreter.execute("blocked()")
236238
elapsed = time.monotonic() - started
239+
release_tool.set()
237240

238-
assert tool_started.wait(timeout=1)
239-
assert elapsed < 0.5
241+
assert tool_started.wait(timeout=5)
242+
assert elapsed < 5
240243
with pytest.raises(CodeInterpreterError, match="shut down"):
241244
interpreter.execute("1")
242245

0 commit comments

Comments
 (0)