[fix][test] Fix flaky TopicListSizeResultCacheTest concurrent requests test#25357
Merged
lhotari merged 2 commits intoapache:masterfrom Mar 19, 2026
Merged
Conversation
…s test The test had two bugs: 1. futures ArrayList was populated from multiple threads without synchronization, causing potential data corruption and lost adds. 2. The test assumed futures.get(0) was the "first" request (the one that wins the CAS in getSizeAsync()), but thread scheduling order is nondeterministic - any thread could add its future to the list first regardless of which called getSizeAsync() first. Fix by using CopyOnWriteArrayList for thread-safe adds, and checking that exactly one future isDone (the CAS winner) without assuming which list index it occupies.
…SizeResultCacheTest
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #25357 +/- ##
=============================================
+ Coverage 37.45% 72.72% +35.26%
- Complexity 13161 34253 +21092
=============================================
Files 1897 1954 +57
Lines 150557 154770 +4213
Branches 17215 17718 +503
=============================================
+ Hits 56398 112550 +56152
+ Misses 86428 33182 -53246
- Partials 7731 9038 +1307
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Flaky test failure
Summary
Fix flaky
TopicListSizeResultCacheTest.testResultHolder_concurrentRequestsWaitForFirstToCompletewhich had two bugs:Unsynchronized
ArrayList:futureslist was populated from multiple threads viafutures.add()without synchronization, causing potential data corruption and lost adds.Wrong ordering assumption: The test assumed
futures.get(0)was the "first" request (the one that wins the CAS ingetSizeAsync()and gets back a completed future). But thread scheduling is nondeterministic — any thread could add its future to the list first regardless of which calledgetSizeAsync()first.Fix
CopyOnWriteArrayListfor thread-safe concurrent addsfutures.get(0)is the CAS winner, count how many futures are done (should be exactly 1) and find it viastream().filter(isDone)updateSize()without assuming index-based orderingVerified with
invocationCount = 100— 100/100 pass.Documentation
doc-not-needed(Your PR doesn't need any doc update)
Matching PR in forked repository
No response
Tip
Add the labels
ready-to-testandarea/testto trigger the CI.