Commit 04e3acb
authored
MINOR: Fix flaky test in ReplicaManagerTest (#21244)
Refer to
#20082 (comment).
Refactored the test to fix a race condition caused by dynamic Mockito
stubbing during test execution.
The previous implementation used `doReturn(false)` and `reset()` on a
spy object while a background thread was running, causing a
`ClassCastException`.
This patch replaces that logic with a thread-safe `AtomicBoolean` and
`doAnswer` approach to toggle the mock's behavior safely.
## Test Command
```
N=100; I=0; while [ $I -lt $N ] && ./gradlew cleanTest core:test --tests
ReplicaManagerTest -PmaxParallelForks=4 \
; do (( I=$I+1 )); echo "Completed run: $I"; sleep 1; done
```
## Test Result
```
BUILD SUCCESSFUL in 12s
151 actionable tasks: 2 executed, 149 up-to-date
Consider enabling configuration cache to speed up this build:
https://docs.gradle.org/9.2.1/userguide/configuration_cache_enabling.html
Completed run: 100
```
Reviewers: Gaurav Narula <[email protected]>, Chia-Ping Tsai
<[email protected]>, PoAn Yang <[email protected]>1 parent 4498998 commit 04e3acb
File tree
1 file changed
+12
-6
lines changed- core/src/test/scala/unit/kafka/server
1 file changed
+12
-6
lines changedLines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| |||
5514 | 5514 | | |
5515 | 5515 | | |
5516 | 5516 | | |
| 5517 | + | |
| 5518 | + | |
| 5519 | + | |
| 5520 | + | |
| 5521 | + | |
| 5522 | + | |
| 5523 | + | |
| 5524 | + | |
| 5525 | + | |
| 5526 | + | |
| 5527 | + | |
5517 | 5528 | | |
5518 | 5529 | | |
5519 | 5530 | | |
| |||
5526 | 5537 | | |
5527 | 5538 | | |
5528 | 5539 | | |
5529 | | - | |
5530 | | - | |
5531 | | - | |
5532 | 5540 | | |
5533 | 5541 | | |
5534 | 5542 | | |
| |||
5537 | 5545 | | |
5538 | 5546 | | |
5539 | 5547 | | |
5540 | | - | |
5541 | | - | |
5542 | 5548 | | |
5543 | 5549 | | |
5544 | 5550 | | |
| |||
0 commit comments