Commit 29d9f2b
committed
Fix race condition in WanCopyRegionFunctionServiceTest
The test severalExecuteWithDifferentRegionOrSenderAreAllowed was failing
intermittently with 'expected: 5 but was: 2/3' due to a race condition.
Root Cause:
The test creates 5 CompletableFuture tasks using supplyAsync(), which
executes asynchronously. There was no guarantee that all tasks would
call service.execute() and be added to the executions map before the
final assertion checked the count.
The race occurred because:
1. CompletableFuture.supplyAsync() schedules tasks asynchronously
2. Multiple tasks could be scheduled but not yet executed
3. The assertion would run before all tasks had called service.execute()
Solution:
Instead of starting all tasks and then waiting, we now start each task
sequentially and wait for it to be registered in the executions map
before starting the next one. This ensures:
- Each execution is fully registered before the next one starts
- No race condition between task scheduling and execution registration
- The final count is guaranteed to be 5
This approach is more deterministic and eliminates the race condition
while still testing that multiple executions with different regions
are allowed to run concurrently.1 parent 9f776b9 commit 29d9f2b
1 file changed
Lines changed: 9 additions & 4 deletions
File tree
- geode-wan/src/test/java/org/apache/geode/cache/wan/internal
Lines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
175 | 181 | | |
176 | 182 | | |
177 | | - | |
178 | | - | |
179 | | - | |
| 183 | + | |
| 184 | + | |
180 | 185 | | |
181 | 186 | | |
182 | 187 | | |
| |||
0 commit comments