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

   Fixes #21287
   
   ### Motivation
   
   Fix two flaky tests in the `pulsar-broker` module:
   
   1. **LeaderElectionServiceTest.anErrorShouldBeThrowBeforeLeaderElected** - 
Fails with `UnfinishedStubbingException` because Mockito stubbing of 
`getLeaderElectionService()` is set up after `pulsar.start()`, allowing 
background threads to interact with the spy during stubbing setup.
   
   2. **PersistentDispatcherFailoverConsumerTest.testAddRemoveConsumer** - 
Fails with `expected object to not be null` because the default 
`activeConsumerFailoverDelayTimeMillis` of 1000ms causes consumer change 
notifications to be scheduled asynchronously via the broker executor with a 
1-second delay, leading to non-deterministic notification ordering.
   
   ### Modifications
   
   - **LeaderElectionServiceTest**: Move Mockito `doAnswer` stubbing of 
`getLeaderElectionService()` to before `pulsar.start()` so no background 
threads are running during stub setup.
   - **PersistentDispatcherFailoverConsumerTest**: Set 
`activeConsumerFailoverDelayTimeMillis` to 0 in the test `ServiceConfiguration` 
to ensure consumer change notifications are dispatched synchronously rather 
than being scheduled with a delay.
   - Added `@Test(invocationCount = 10)` to both tests to verify stability.
   
   ### Verifying this change
   
   This change is verified by running the fixed tests with `invocationCount = 
10`:
   
   - `LeaderElectionServiceTest.anErrorShouldBeThrowBeforeLeaderElected` - 
10/10 passed
   - `PersistentDispatcherFailoverConsumerTest.testAddRemoveConsumer` - 10/10 
passed
   
   ### 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