Skip to content

[fix][test] Fix Mockito stubbing race in TopicListServiceTest#25227

Open
Denovo1998 wants to merge 1 commit intoapache:masterfrom
Denovo1998:fix_testCommandWatchUpdateRetries
Open

[fix][test] Fix Mockito stubbing race in TopicListServiceTest#25227
Denovo1998 wants to merge 1 commit intoapache:masterfrom
Denovo1998:fix_testCommandWatchUpdateRetries

Conversation

@Denovo1998
Copy link
Contributor

@Denovo1998 Denovo1998 commented Feb 7, 2026

Fixes #25226

Main Issue: #xyz

PIP: #xyz

Motivation

TopicListServiceTest#testCommandWatchUpdateRetries could intermittently fail with a NullPointerException and Mockito UnfinishedStubbingException due to a race between async watcher callbacks and Mockito stubbing.

In particular, the test was setting up doAnswer().when(pulsarCommandSender)... after starting async work, so another thread could invoke methods on the same mock while Mockito was still in “stubbing in progress” state. This made the test flaky and caused occasional false failures.

Modifications

  • Move the sendWatchTopicListUpdate stubbing to happen before handleWatchTopicList(...) starts any asynchronous processing.
  • Add a short comment to document why the ordering is important (avoid concurrent Mockito stubbing state).

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: Denovo1998#20

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for fixing!

@lhotari
Copy link
Member

lhotari commented Feb 7, 2026

/pulsarbot rerun-failure-checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky-test: TopicListServiceTest.testCommandWatchUpdateRetries has mockito stubbing race

2 participants