Make the `Dataset.evaluate` sync-task timeout test and the batch-filling test independent of runner speed

Merged
DO
1mo ago
+24-12

Two tests that failed intermittently in merge-queue and main CI on loaded runners, changed to check the same behavior at any speed:

  • tests/evals/test_dataset.py::test_task_timeout_abandons_sync_task_thread (failed on test on 3.13/3.14 (pydantic-evals) in 6 of the last ~4 days' failed runs, e.g. run 40783410745, with assert await anyio.to_thread.run_sync(finished.wait, ...) → assert False). With task_timeout=0.01, a worker thread that takes over 10 ms to pick the task up finds the job already cancelled, and anyio's worker skips a cancelled job, so the task never runs and finished is never set. The test now moves the event loop's clock (the shared tests/clock_utils.py Clock) past LONG_TIMEOUT only once the task has signalled that it is running.
  • tests/models/test_batch_runs.py::test_many_concurrent_runs_fill_batches_of_the_default_size (over the 8 s per-test budget at 8.6 s, in 9 failed runs, e.g. on #11793's CI): 1,050 agent runs to fill one 1,000-request batch. It now pins the default max_requests of 1,000 directly and fills batches of max_requests=10 with 25 runs, as "Test cost" in tests/AGENTS.md asks; renamed test_many_concurrent_runs_fill_batches_of_max_requests. 0.07 s instead of 2.3 s locally. #12166 has since kept the old test within budget by limiting its garbage collections (young_gc), which this test keeps; this change removes the 1,050 runs themselves.

Verification:

  • A pytest plugin that makes anyio's worker thread take 50 ms to dequeue its job makes the old sync-task test fail with CI's assert False; the new one passes under it, normally, and with --anyio-backend=trio (pinned to asyncio like tests/test_request_timeout.py, as it patches the asyncio loop's clock).
  • Both tests pass; ruff and pyright are clean on both files.

What changes for existing users: nothing, test-only.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

Summary by cubic

Makes two flaky tests in tests/evals/test_dataset.py and tests/models/test_batch_runs.py deterministic regardless of runner speed, with no behavior changes for users.

  • The sync-task timeout test no longer depends on a worker thread picking up the task within 10 ms; it now advances the test clock only after the task signals it is running.
  • The batch-filling test now pins max_requests=10 and fills batches with 25 runs instead of filling a 1,000-request batch with 1,050 runs, cutting its runtime from seconds to milliseconds.