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 flaky ReplicatorTest.testReplicatorProducerNameWithUserDefinedReplicatorPrefix by merlimat · Pull Request #27407 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Motivation

ReplicatorTest.testReplicatorProducerNameWithUserDefinedReplicatorPrefix ("CI - Unit - Brokers - Broker Group 5") fails now and then with:

java.lang.AssertionError: expected [true] but found [false]
    at org.apache.pulsar.broker.service.ReplicatorTest.testReplicatorProducerNameWithUserDefinedReplicatorPrefix(ReplicatorTest.java:1063)

The test produces to a topic on r1, waits until the topic exists on r2, and then checks once that one of the r2 topic's producers is r1's replicator:

Awaitility.await().untilAsserted(()->{
    assertTrue(pulsar2.getBrokerService().getTopicReference(topicName).isPresent());
});
Optional<Topic> topic = pulsar2.getBrokerService().getTopicReference(topicName);
assertTrue(topic.isPresent());
Set<String> remoteClusters = topic.get().getProducers().values().stream()
        .map(org.apache.pulsar.broker.service.Producer::getRemoteCluster)
        .collect(Collectors.toSet());
assertTrue(remoteClusters.contains("r1"));   // expected [true] but found [false]

The topic on r2 doesn't show that r1's replicator producer is attached. Before it creates its producer, GeoPersistentReplicator.prepareCreateProducer() creates the remote topic with the admin API (createNonPartitionedTopicAsync, when createTopicToRemoteClusterForReplication is on, the default). That call loads the topic on r2. The replicator then looks the topic up and creates its producer. In the failed CI run, the topic on r2 was loaded 30 ms before r1's producer attached on the first attempt, and 115 ms before on the retry, which restarts the clusters. The check ran in that window both times. r3's replicator producer can attach first, so the set was [] or [r3].

The sibling testReplicatorProducerName had the same flake (#12897). #12898 fixed it by waiting for the producer. This method, added in #12797, kept the unfixed check.

The replicator is correct: its producer attaches right after the remote topic is created.

Modifications

Wait for r1's replicator producer to attach on r2 instead of checking once, as testReplicatorProducerName does:

// r1's replicator creates the topic on r2 through the admin API before it creates its producer.
Awaitility.await().untilAsserted(() -> {
    Set<String> remoteClusters = topic.get().getProducers().values().stream()
            .map(org.apache.pulsar.broker.service.Producer::getRemoteCluster)
            .collect(Collectors.toSet());
    assertTrue(remoteClusters.contains("r1"));
});

Test-only change.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as ReplicatorTest, and was verified as follows:

  • Deterministic reproduction: a temporary spy on r1's replication client for r2 held the replicator's createProducerAsync for the test topic until the check had run. The remote topic still got created, so the test failed 3 of 3 with the CI error, seeing [] once and [r3] twice.
  • With this change and the same hold, released only once a check had seen r1 missing, the first check saw [r3] and the test passed 3 of 3 after r1's producer attached.
  • Without the injection, testReplicatorProducerName* passed 3 of 3, the whole ReplicatorTest class passed with retries off (49 tests, no failures), and ./gradlew quickCheck passes.

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
@merlimat
[fix][test] Fix flaky ReplicatorTest.testReplicatorProducerNameWithUs…
2e436ff
…erDefinedReplicatorPrefix

The test waited until the topic existed on r2 and then checked once that
r1's replicator producer was attached. The replicator creates the remote
topic through the admin API before it creates its producer, so the topic
is present on r2 for tens of milliseconds before r1's producer attaches,
and a check in that window fails with "expected [true] but found [false]".

Wait for the producer instead, as testReplicatorProducerName does since
apache#12898.
@merlimat merlimat added the area/test label Nov 6, 2026
void-ptr974
void-ptr974 approved these changes Nov 6, 2026
View reviewed changes
codelipenghui
codelipenghui approved these changes Nov 6, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Code Review approval for commit 2e436ff.

Summary:

No actionable findings identified within the reviewed scope. The Awaitility change waits for r1's producer without weakening custom-prefix recognition. Both focused tests passed with retries disabled; the pre-fix baseline also passed, so the intermittent failure was not reproduced.

Sorry, something went wrong.

Uh oh!

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

All reactions
@codelipenghui
codelipenghui merged commit 10b9b24 into apache:master Nov 6, 2026
43 checks passed

Uh oh!

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

lhotari pushed a commit that referenced this pull request Nov 9, 2026
@merlimat @lhotari
[fix][test] Fix flaky ReplicatorTest.testReplicatorProducerNameWithUs…
302bf36
…erDefinedReplicatorPrefix (#27407)

(cherry picked from commit 10b9b24)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 9, 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
@merlimat @lhotari
[fix][test] Fix flaky ReplicatorTest.testReplicatorProducerNameWithUs…
739ada6
…erDefinedReplicatorPrefix (apache#27407)

(cherry picked from commit 10b9b24)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][test] Fix flaky ReplicatorTest.testReplicatorProducerNameWithUs…
ab48e14
…erDefinedReplicatorPrefix (apache#27407)

(cherry picked from commit 10b9b24)
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
+1 more reviewer
@void-ptr974 void-ptr974 void-ptr974 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

area/test 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.

4 participants

@merlimat @codelipenghui @void-ptr974 @lhotari
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.