Skip to content

fix(test): stop ModuleEnvironmentWatcherTest racing WatchService delivery - #173

Open
soloturn wants to merge 1 commit into
developfrom
fix-flaky-watcher-test
Open

fix(test): stop ModuleEnvironmentWatcherTest racing WatchService delivery#173
soloturn wants to merge 1 commit into
developfrom
fix-flaky-watcher-test

Conversation

@soloturn

Copy link
Copy Markdown
Contributor

Closes #172.

Root cause was not mtime resolution (my first guess) - it's java.nio.file.WatchService. ModuleEnvironmentWatcher.checkForChanges() does a single non-blocking service.poll(), but the OS delivers file events asynchronously (inotify/FSEvents/etc.) - a change made just before calling it can still be in flight and not show up in that one poll, especially under CI's slower/virtualized filesystems.

The test asserted on a single checkForChanges() call right after each filesystem mutation, racing ahead of event delivery. Verified this reproduces on a clean develop checkout with zero changes (not something #171 introduced).

Fix: added an awaitChange() helper that retries checkForChanges() for up to 5s (20ms between polls) instead of asserting on a single poll's result, and used it for both file-created and file-modified assertions. No production code touched - this is purely a test-robustness fix; ModuleEnvironmentWatcher itself already handles delayed events correctly (a late-processed directory-creation event still picks up files already inside it via a directory rescan), it's only the test's single-shot assertion that was racing.

Test plan:

  • Ran the test 3x locally with --rerun after the fix, all green (it reliably failed before, both on this branch's prior state and on unmodified develop)
  • ./gradlew :gestalt-asset-core:build succeeds

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 35 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c00aef35-5392-45ee-8c61-42497d7316db

📥 Commits

Reviewing files that changed from the base of the PR and between 8428809 and aec3dd9.

📒 Files selected for processing (1)
  • gestalt-asset-core/src/test/java/org/terasology/gestalt/assets/module/autoreload/ModuleEnvironmentWatcherTest.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModuleEnvironmentWatcherTest.test is flaky (mtime-resolution race)

1 participant