GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][test] Fix Mockito stubbing race in NamespaceServiceSplitFailureTest that breaks later metrics tests by lhotari · Pull Request #27582 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Nov 11, 2026

Copy link
Copy Markdown
Member

Motivation

TopicDispatchRateLimiterTest.testTopicDispatchThrottledMetrics failed in CI (Broker Group 1, run), and its retry failed too, with:

org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
CoordinationServiceImpl cannot be returned by getConfig()
    at org.apache.pulsar.broker.PulsarService.getConfig(PulsarService.java:232)
    at org.apache.pulsar.broker.service.BrokerService.getPendingTopicLoadRequests(BrokerService.java:600)
    at org.apache.pulsar.broker.stats.prometheus.metrics.ObserverGauge.collect(ObserverGauge.java:96)
    ...

That test is not the cause. NamespaceServiceSplitFailureTest ran earlier in the same test JVM. Its test report shows testSplitFailsWhenBundleCacheLoadFails[2](false) skipped with CoordinationServiceImpl cannot be returned by getState():

  • The test builds a non-startable PulsarTestContext, which creates the BrokerService and its metadata listeners in the constructor.
  • After that, the test stubs the running PulsarService spy with doReturn(coordinationService).when(pulsar).getCoordinationService().
  • Mockito keeps a doReturn(...).when(spy) stubbing in progress on the mock itself. A metadata-event thread called pulsar.getState() in the middle of the stubbing call and took the pending answer.
  • When that happens, Mockito leaves the pending answer stuck on the spy, so every later call on it throws.
  • The broker's ObserverGauge collectors live in the JVM-wide default Prometheus registry and still point at the broken spy. Any later metrics scrape in the same JVM fails, including the retry of testTopicDispatchThrottledMetrics.

#27090 fixed the same race for this class's SplitContext helper, but testSplitFailsWhenBundleCacheLoadFails was still stubbing a live spy.

Modifications

  • testSplitFailsWhenBundleCacheLoadFails now uses the same approach as SplitContext:
    • A startable context with ModularLoadManagerImpl.
    • A doAnswer stub for PulsarService.getPulsarResources(), installed in pulsarServiceCustomizer before the broker starts, so no other thread can be calling the spy yet. It calls the real method until the test sets an override.
  • The PulsarResources and LocalPoliciesResources spies that make the policies load fail are new objects. They are stubbed before any other thread can see them and then switched in through an AtomicReference.
  • Because a started broker has a real coordination service and ordered executor, the test no longer stubs getCoordinationService() and getOrderedExecutor(). It also uses the broker's own NamespaceService instead of constructing a second one.
  • The scenario and assertions are unchanged: the bundle cache is empty, the policies load is already failed or still pending, and the split must fail with ServiceUnitNotReadyException.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as NamespaceServiceSplitFailureTest.testSplitFailsWhenBundleCacheLoadFails:

  • Verified locally with invocationCount = 10: 20/20 invocations across both data-provider values passed, with none skipped.
  • With the override line removed, both cases fail, so the injected policies failure is still what the test exercises.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lhotari
[fix][test] Fix Mockito stubbing race in NamespaceServiceSplitFailure…
e632381
…Test.testSplitFailsWhenBundleCacheLoadFails

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari
lhotari requested review from Denovo1998, Technoboy-, codelipenghui, dao-jun, merlimat and nodece November 11, 2026 15:30
codelipenghui
codelipenghui approved these changes Nov 11, 2026
View reviewed changes
@lhotari
lhotari merged commit 5b0e0d9 into apache:master Nov 11, 2026
43 checks passed

Uh oh!

There was an error while loading. Please reload this page.

lhotari added a commit that referenced this pull request Nov 11, 2026
@lhotari
[fix][test] Fix Mockito stubbing race in NamespaceServiceSplitFailure…
a40fcf8
…Test that breaks later metrics tests (#27582)

(cherry picked from commit 5b0e0d9)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 11, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@lhotari
[fix][test] Fix Mockito stubbing race in NamespaceServiceSplitFailure…
35ebcc1
…Test that breaks later metrics tests (apache#27582)

(cherry picked from commit 5b0e0d9)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@lhotari
[fix][test] Fix Mockito stubbing race in NamespaceServiceSplitFailure…
096dc38
…Test that breaks later metrics tests (apache#27582)

(cherry picked from commit 5b0e0d9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes
@merlimat merlimat Awaiting requested review from merlimat
@nodece nodece Awaiting requested review from nodece
@dao-jun dao-jun Awaiting requested review from dao-jun
@Technoboy- Technoboy- Awaiting requested review from Technoboy-
@Denovo1998 Denovo1998 Awaiting requested review from Denovo1998

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@lhotari @codelipenghui
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.