fix: flaky cache test
Which issue does this PR close?
- Closes https://github.com/apache/datafusion/issues/19114.
Rationale for this change
The test test_cache_with_ttl_and_lru was flaky and failing intermittently in CI. It relied on std::thread::sleep and Instant::now(), which caused race conditions when the test environment was slow or under load. This PR makes the test correct by removing reliance on the system clock and thread sleeping.
What changes are included in this PR?
-> Introduced a TimeProvider trait to abstract time retrieval.
-> Refactored DefaultListFilesCache to use provider.
-> Added DefaultListFilesCache::new_with_provider for testing purposes.
-> Updated test_cache_with_ttl_and_lru to use a MockTimeProvider.
Are these changes tested?
Yes. I verified the fix by running the specific test locally without failure.
Are there any user-facing changes?
No.
FYI @BlakeOrth
@adriangb all suggested changes are made . Thanks
I am trying to clean up the PR review / merge queue, so I took the liberty of implementing @BlakeOrth 's suggestions about comments and merging up from main to resolve conflicts
Thank you @BlakeOrth and @xonx4l and @adriangb