-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.nio.file.WatchService is missing events sometimes #277
Comments
I've encountered similar issues in other projects due to millisecond precision in event detection. Your observation about the rapid succession of events within the same millisecond seems spot on. A potential solution might be to use a more granular timestamp, such as nanoseconds, or incorporate a short buffer mechanism to account for rapid changes. Your workaround with the 1ms sleep is a good short-term fix, but it might be beneficial for the library to handle such scenarios natively. |
I think this is probably blocked on jimfs being able to use a better time source than
We could try to get a bit fancy (cough hacky cough) here and use a reflective check to see if |
Hey, a few thoughts:
|
Fixes #277 RELNOTES=n/a PiperOrigin-RevId: 575796090
Hi,
thanks for your work on this great library. It makes a lot of my unit test easy to write and very fast!
Yesterday, I tried to use JimFS for a Class that uses the java.nio.file.WatchService
I registered it using
In the test I just added one file into the watched directory and wait for the create event to happen.
The problem is, that sometimes file changes are not detected (no event).
And I may already found the reason for it. At
JimFS detects changes by comparing the timestamps of a modification with the previous one and it does it only with milliseconds precision. If the test runs to quickly so that the new modification happens in the same millisecond, no event will be pushed.
If I modify my test to sleep for 1ms before adding/changing files, the problem no longer appears.
My system: Ubuntu 22.04
Test-Runner: JUnit 5
JimFSConfiguration:
If you need any more information, please let me know.
The text was updated successfully, but these errors were encountered: