Fix IndicesRequestCacheCleanupIT flakiness by removing too-short assertBusy timeouts - #21494
Conversation
…rtBusy timeouts The test class passed a custom timeout of `cacheCleanIntervalInMillis * MAX_ITERATIONS` (with MAX_ITERATIONS = 5) to every assertBusy call. With cacheCleanIntervalInMillis set to 1, 10, 50, or 100 ms across the tests, the wall-clock timeout budget ranged from just 5 ms to 500 ms for async cluster operations (flush, force-merge, scheduled cleanup, stats propagation). On loaded CI agents the cleanup thread or stats propagation would regularly miss this window, producing an AssertionError that has no actual race behind it. Drop the custom timeouts and rely on assertBusy's default 10-second budget, matching the rest of the codebase's convention for async cluster assertions. assertBusy returns on the first successful iteration, so tests that assert a steady-state negative condition (cleanup should NOT have happened) still return in constant time — only the failure path gets the larger budget. Also remove the now-unused MAX_ITERATIONS constant and TimeUnit import. Ran locally on the modified tests with -Dtests.iters=5..10: 25 iterations across 4 previously-flaky methods, all green. Relates to opensearch-project#21397 Signed-off-by: Andre Kurait <andrekurait@gmail.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
❕ Gradle check result for fe5c681: UNSTABLE Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21494 +/- ##
============================================
+ Coverage 73.44% 73.49% +0.04%
- Complexity 74429 74466 +37
============================================
Files 5970 5970
Lines 338276 338262 -14
Branches 48760 48758 -2
============================================
+ Hits 248453 248603 +150
+ Misses 69979 69854 -125
+ Partials 19844 19805 -39 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…rtBusy timeouts (opensearch-project#21494) The test class passed a custom timeout of `cacheCleanIntervalInMillis * MAX_ITERATIONS` (with MAX_ITERATIONS = 5) to every assertBusy call. With cacheCleanIntervalInMillis set to 1, 10, 50, or 100 ms across the tests, the wall-clock timeout budget ranged from just 5 ms to 500 ms for async cluster operations (flush, force-merge, scheduled cleanup, stats propagation). On loaded CI agents the cleanup thread or stats propagation would regularly miss this window, producing an AssertionError that has no actual race behind it. Drop the custom timeouts and rely on assertBusy's default 10-second budget, matching the rest of the codebase's convention for async cluster assertions. assertBusy returns on the first successful iteration, so tests that assert a steady-state negative condition (cleanup should NOT have happened) still return in constant time — only the failure path gets the larger budget. Also remove the now-unused MAX_ITERATIONS constant and TimeUnit import. Ran locally on the modified tests with -Dtests.iters=5..10: 25 iterations across 4 previously-flaky methods, all green. Relates to opensearch-project#21397 Signed-off-by: Andre Kurait <andrekurait@gmail.com>
…rtBusy timeouts (opensearch-project#21494) The test class passed a custom timeout of `cacheCleanIntervalInMillis * MAX_ITERATIONS` (with MAX_ITERATIONS = 5) to every assertBusy call. With cacheCleanIntervalInMillis set to 1, 10, 50, or 100 ms across the tests, the wall-clock timeout budget ranged from just 5 ms to 500 ms for async cluster operations (flush, force-merge, scheduled cleanup, stats propagation). On loaded CI agents the cleanup thread or stats propagation would regularly miss this window, producing an AssertionError that has no actual race behind it. Drop the custom timeouts and rely on assertBusy's default 10-second budget, matching the rest of the codebase's convention for async cluster assertions. assertBusy returns on the first successful iteration, so tests that assert a steady-state negative condition (cleanup should NOT have happened) still return in constant time — only the failure path gets the larger budget. Also remove the now-unused MAX_ITERATIONS constant and TimeUnit import. Ran locally on the modified tests with -Dtests.iters=5..10: 25 iterations across 4 previously-flaky methods, all green. Relates to opensearch-project#21397 Signed-off-by: Andre Kurait <andrekurait@gmail.com>
Description
Fixes long-standing flakiness in
IndicesRequestCacheCleanupITby removingtoo-short custom timeouts on every
assertBusycall.Root cause. Every
assertBusyin the file passedcacheCleanIntervalInMillis * MAX_ITERATIONS(withMAX_ITERATIONS = 5)as the wall-clock timeout. The
cacheCleanIntervalInMillisvalues set pertest were
1,10,50, or100ms — yielding timeout budgets of just5 ms, 50 ms, 250 ms, or 500 ms for async cluster operations (flush,
force-merge, scheduled cache-cleanup, stats propagation across nodes).
Under normal CI load these windows are routinely missed; the resulting
AssertionErrorhas no race behind it — the test just ran out of timewhile the cluster was still converging.
Evidence that this is timeout sizing, not a product race:
shows
AssertionErrorat the assertion line, not a timeout/interruptexception.
uses the buggy pattern — a 1:1 overlap.
default 10-s budget.
Fix. Drop the custom timeout on all 12
assertBusycall sites andrely on
assertBusy's default 10-second budget, which is the conventionelsewhere in the codebase for async cluster assertions. Also remove the
now-unused
MAX_ITERATIONSconstant andjava.util.concurrent.TimeUnitimport.
Why this is safe for the "negative" tests (e.g.
testCacheCleanupSkipsWithHighStalenessThreshold, which asserts cleanupdid not happen):
assertBusyreturns on the first successfuliteration, so the 10-s budget is a no-op on passing runs — it only
extends the failure path.
cacheCleanIntervalInMillisvalues themselves are unchanged — theylegitimately configure the cleaner thread cadence so the test can observe
cleanup quickly; only the test's wall-clock deadline was wrong.
Related Issues
Relates to #21397
Verification
Ran locally on the modified file against a fresh
main:25 consecutive passes across 4 of the previously-flaky methods.
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.