datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

fix: flaky cache test

Open xonx4l opened this issue 1 month ago • 2 comments

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.

xonx4l avatar Dec 07 '25 06:12 xonx4l

FYI @BlakeOrth

alamb avatar Dec 07 '25 11:12 alamb

@adriangb all suggested changes are made . Thanks

xonx4l avatar Dec 08 '25 07:12 xonx4l

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

alamb avatar Dec 11 '25 22:12 alamb

Thank you @BlakeOrth and @xonx4l and @adriangb

alamb avatar Dec 11 '25 22:12 alamb