Drain file watcher events during test setup#24030
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 85.29%. The percentage of expected errors that received a diagnostic held steady at 78.13%. The number of fully passing files held steady at 64/132. |
Memory usage reportMemory usage unchanged ✅ |
|
| // This ensures the FSEvents stream (on macOS) is fully started before the test | ||
| // proceeds, preventing flakes where events are lost during stream restart. | ||
| let sentinel_path = project_path.join(".watcher_ready"); | ||
| std::fs::write(sentinel_path.as_std_path(), "ready")?; |
There was a problem hiding this comment.
Can you say more why this should fix the issue? I'm not very convinced that it does :)
ruff/crates/ty/tests/file_watching.rs
Lines 1532 to 1533 in 5879601
does wait for a file system event related to baz.py, which we did observe in https://github.com/astral-sh/ruff/actions/runs/20860850768/job/59939819903?pr=22481, but the test still failed.
If the concern really is that it sometimes takes too long for the file watcher to start, then the solution is to bump the default timeout here
ruff/crates/ty/tests/file_watching.rs
Line 70 in 5879601
There was a problem hiding this comment.
I think there are two things going for the approach in this PR:
- it ensures that the watcher is working well, and not e.g. backed up with events from before the current test
- flushes events unrelated to the current test a lot better than the previous
test_case.try_take_watch_changes(|_| true, ...)
I suspect what's going on in https://github.com/astral-sh/ruff/actions/runs/20860850768/job/59939819903?pr=22481 is that there are multiple events emitted by the file watcher that aren't related to the symlink_inside_project test case, but still leak into them.
Edit: open to suggestions about how to better explain this in the comment :)
There was a problem hiding this comment.
Thank you. I think we can copy exactly what you wrote here into the comment.
MichaReiser
left a comment
There was a problem hiding this comment.
Thanks. Let's give this a try
| // This ensures the FSEvents stream (on macOS) is fully started before the test | ||
| // proceeds, preventing flakes where events are lost during stream restart. | ||
| let sentinel_path = project_path.join(".watcher_ready"); | ||
| std::fs::write(sentinel_path.as_std_path(), "ready")?; |
There was a problem hiding this comment.
Thank you. I think we can copy exactly what you wrote here into the comment.
4578a19 to
e986d47
Compare
See astral-sh/ty#1540, I believe this PR should solve the remaining two issues in there.