[fix][test] Recreate EventLoop in PublishRateLimiterTest setup - #25560
Merged
Conversation
The class-level `eventLoop` field was created once at instance construction and shut down by `@AfterMethod tearDown()`, but never re-created. TestNG reuses a single class instance across methods, so the second test to run in the class hit `RejectedExecutionException: event executor terminated` when it called `eventLoop.execute(...)`. Two recent additions to this class (`shouldUnthrottleImmediately…`) exposed the latent bug — in alphabetical TestNG order, they run before `testPublishRateLimiterImplExceed` and their `tearDown` terminates the shared event loop. Move `eventLoop` creation into `@BeforeMethod` so each test gets a fresh one.
lhotari
approved these changes
Apr 21, 2026
lhotari
pushed a commit
that referenced
this pull request
Apr 21, 2026
(cherry picked from commit 293eafc)
lhotari
pushed a commit
that referenced
this pull request
Apr 21, 2026
(cherry picked from commit 293eafc)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PublishRateLimiterTesthas a latent bug: the class-leveleventLoopfield is initialized once (at instance construction), but
@AfterMethod tearDown()callseventLoop.shutdownGracefully()afterevery test. TestNG reuses a single instance per class, so the second
test method to run in the class hits
RejectedExecutionException: event executor terminatedwhen it callseventLoop.execute(...).Two recent additions to the class
(
shouldUnthrottleImmediatelyAfterDisablingLimitsDespiteLongPendingDelayand
shouldUnthrottleImmediatelyAfterRaisingByteLimitDespiteLongPendingDelay,added in #25502) exposed the latent bug — in TestNG's alphabetical
default order, they run before
testPublishRateLimiterImplExceed, andtheir
tearDownterminates the shared event loop.The fix: move
eventLoopcreation into@BeforeMethodso each testgets a fresh instance.
@AfterMethod tearDown()continues to shutit down at the end of each test.
Test plan
./gradlew :pulsar-broker:test --tests "org.apache.pulsar.broker.service.PublishRateLimiterTest"all 4 tests pass.