lhotari opened a new pull request, #26123:
URL: https://github.com/apache/pulsar/pull/26123

   ### Motivation
   
   `ManagedLedgerTest.makeReadEntryProbFail` installs a Mockito answer on
   `LedgerHandle.readUnconfirmedAsync` that consults a caller-supplied
   `Supplier<ManagedLedgerException>` (`errorOrNot`) to decide whether a read 
should
   fail. That supplier was evaluated directly on the thread that calls
   `readUnconfirmedAsync`.
   
   When a test supplies a *blocking* `errorOrNot`, that read thread is held for 
the
   whole duration of the block, which can stall or deadlock the test. For 
example,
   
`PersistentReplicatorInflightTaskTest#testReadEntriesFailedCompletesInFlightTaskAfterReplicatorTerminated`
   (added in #25767) blocks in `errorOrNot` on a `CountDownLatch` until the test
   releases it after terminating the replicator. Because the calling thread was
   blocked, the test flow could not make progress and its
   `failRead.await(30, SECONDS)` always timed out.
   
   ### Modifications
   
   - Evaluate `errorOrNot` via `CompletableFuture.supplyAsync(...)` so it runs 
on
     `ForkJoinPool.commonPool()` instead of the calling thread, then compose the
     resulting read future with `thenCompose`. The calling thread is no longer
     blocked while a test's `errorOrNot` waits.
   - Simplify the answer body while doing so: drop the intermediate
     `CompletableFuture<CompletableFuture<LedgerEntries>>` locals and the
     `Function.identity()` import.
   
   This only touches test code (`ManagedLedgerTest`); production code is 
unaffected.
   
   ### Verifying this change
   
   This change is already covered by existing tests that use 
`makeReadEntryProbFail`
   (`PersistentReplicatorInflightTaskTest`, `OneWayReplicatorTest`).
   
   Verified locally:
   
   ```
   ./gradlew :pulsar-broker:test --tests 
"org.apache.pulsar.broker.service.persistent.PersistentReplicatorInflightTaskTest"
   ```
   
   passes (15 tests, 0 failures), including
   `testReadEntriesFailedCompletesInFlightTaskAfterReplicatorTerminated`
   (~1s; it previously timed out because the caller thread was blocked).
   
   - [ ] Make sure that the change passes the CI checks.
   
   ### Does this pull request potentially affect one of the following parts:
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   


-- 
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]

Reply via email to