merlimat opened a new pull request, #25357:
URL: https://github.com/apache/pulsar/pull/25357
## Flaky test failure
```
java.lang.AssertionError: expected [true] but found [false]
at org.testng.Assert.assertTrue(Assert.java:56)
at
org.apache.pulsar.broker.topiclistlimit.TopicListSizeResultCacheTest.testResultHolder_concurrentRequestsWaitForFirstToComplete(TopicListSizeResultCacheTest.java:132)
```
## Summary
Fix flaky
`TopicListSizeResultCacheTest.testResultHolder_concurrentRequestsWaitForFirstToComplete`
which had two bugs:
1. **Unsynchronized `ArrayList`**: `futures` list was populated from
multiple threads via `futures.add()` without synchronization, causing potential
data corruption and lost adds.
2. **Wrong ordering assumption**: The test assumed `futures.get(0)` was the
"first" request (the one that wins the CAS in `getSizeAsync()` and gets back a
completed future). But thread scheduling is nondeterministic — any thread could
add its future to the list first regardless of which called `getSizeAsync()`
first.
### Fix
- Use `CopyOnWriteArrayList` for thread-safe concurrent adds
- Instead of assuming `futures.get(0)` is the CAS winner, count how many
futures are done (should be exactly 1) and find it via `stream().filter(isDone)`
- Verify all futures complete after `updateSize()` without assuming
index-based ordering
Verified with `invocationCount = 100` — 100/100 pass.
## Documentation
- [x] `doc-not-needed`
(Your PR doesn't need any doc update)
## Matching PR in forked repository
_No response_
### Tip
Add the labels `ready-to-test` and `area/test` to trigger the CI.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]