Fix flaky FileTrigger/FileDeleteTrigger tests by awaiting the task#66825
Merged
Conversation
jscheffl
approved these changes
May 12, 2026
bugraoz93
approved these changes
May 12, 2026
`test_task_file_trigger` and `test_file_delete_trigger` waited
`asyncio.sleep(0.5)` after `p.touch()` and then asserted on the
trigger's effect (task.done() / file gone). The trigger has to wake
from its poll-interval sleep, run `is_file()`, run `stat()`, (for the
delete variant) run `unlink()`, log, and yield. With anyio's thread-
pool-backed file ops, 0.5s isn't always enough on slow runners — the
Pendulum2 ARM job repeatedly hits the race in `test_file_delete_trigger`
("Found file" is logged but unlink hasn't returned by the time the
assertion runs).
Switch to `await asyncio.wait_for(task, timeout=5.0)` so the assertion
can't race the trigger's detect → yield cycle. Once the task is done,
the trigger has completed all its work (including unlink for the
delete trigger), so the file-existence assertion is deterministic.
Also drop the `asyncio.get_event_loop().stop()` cleanup line. It was
protecting against the pending task left behind by the fixed-sleep
pattern; with `wait_for`, there's no pending task and pytest-asyncio's
own teardown handles loop lifecycle.
e509262 to
6b3a5c5
Compare
This was referenced May 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test_task_file_triggerandtest_file_delete_triggerinproviders/standard/tests/unit/standard/triggers/test_file.pywaited a fixedasyncio.sleep(0.5)afterp.touch()and then asserted on the trigger's effect. On the Pendulum2 ARM scheduled job (failing run) thetest_file_delete_triggerrace fires: captured stdout showsFound file …but the unlink hasn't returned by the time the assertion runs, soawait anyio.Path(p).exists() is Falsefails withassert True is False.The trigger has to wake from its
poke_interval=0.2sleep, runis_file(),stat(),unlink(), log, and yield — all anyio thread-pool-backed file ops. 0.5s isn't always enough on slow runners.Fix
Switch to
await asyncio.wait_for(task, timeout=5.0)so the assertion can't race the trigger's detect → (unlink) → yield cycle. Once the task is done, the trigger has completed all its work, so the file-existence assertion (for the delete variant) andtask.done() is True(for the wait variant) are deterministic.Also drop the trailing
asyncio.get_event_loop().stop()cleanup line. It was a workaround for the pending task left behind by the fixed-sleep pattern; withwait_for, there's no pending task and pytest-asyncio's own teardown handles loop lifecycle.Test plan
uv run --project providers/standard pytest providers/standard/tests/unit/standard/triggers/test_file.py -xvs(both tests pass)related: #61616 (the anyio conversion that made the unlink path async)
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.7) following the guidelines