[fix][test] Avoid unsafe cleanup between shared-cluster tests - #26611
Merged
Merged
Conversation
Shared Pulsar clusters keep their worker threads alive between test classes. FastThreadLocal cleanup modifies those live threads without synchronization, and Mockito cleanup similarly mutates their internal ThreadLocal maps. Remove both listeners and their default registrations to avoid racing shared infrastructure. Keep explicit cleaner utilities available. Other registered listeners do not perform equivalent cross-thread state cleanup; shared clusters already reset the thread leak detector baseline. Validation: ./gradlew quickCheck and 12 tests from BetweenTestClassesListenerAdapterTest and FastThreadLocalStateCleanerTest with testRetryCount=0. Assisted-by: Codex
Replace shared-worker mocks with real cursors, channels, entry filters, and narrow subclasses. Test metadata entry release and TTL fallback through package-private helpers instead of modifying shared broker internals. Explicitly release test-owned mocks and annotation fixtures, restore the broker interceptor, and monitor the executor actually used for multi-topic retries. Validation: quickCheck and 82 scoped test cases passed with retries disabled. Assisted-by: Codex
lhotari
requested review from
Technoboy-,
dao-jun,
david-streamlio,
merlimat and
nodece
September 16, 2026 22:14
The removed listener was its only caller. Delete the cleaner and its tests, and update the Netty dependency comment. Assisted-by: Codex
merlimat
approved these changes
Sep 17, 2026
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.
Motivation
SharedPulsarCluster keeps broker resources and worker threads alive across test classes. FastThreadLocalCleanupListener removes Netty fast-thread-local state between classes, while MockitoCleanupListener reflects into live workers' thread-local maps and performs global inline-mock cleanup. These operations can interfere with resources still owned by the shared cluster.
Global mock cleanup also does not solve ownership: Mockito invocations on a long-lived worker can retain ongoing-stubbing state and its mock graph on that worker. Clearing mocks from a different thread does not remove those references. Tests should avoid invoking mocks on shared workers and explicitly release fixtures they own.
Modifications
Verifying this change
./gradlew spotlessCheck checkstyleMain checkstyleTestand./gradlew quickCheckpassed.Does this pull request potentially affect one of the following parts: