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 ResourceGroupUsageAggregationTest.testProduceConsumeUsageOnRG by merlimat · Pull Request #27446 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Motivation

ResourceGroupUsageAggregationTest.testProduceConsumeUsageOnRG failed both attempts in
CI - Unit - Brokers - Broker Group 2 of #27443
(job), a PR that only changes
SegmentOwnerStateTest:

java.lang.AssertionError: expected [20] but found [10]
    at ResourceGroupUsageAggregationTest.verifyStats(ResourceGroupUsageAggregationTest.java:240)
    at ResourceGroupUsageAggregationTest.testProduceConsumeUsageOnRG(ResourceGroupUsageAggregationTest.java:156)

After the test sent 10 messages to its topic, the resource group's cumulative publish usage was 20.

The test aggregates the usage itself (rgs.aggregateResourceGroupLocalUsages()), but the ResourceGroupService it
builds also runs that aggregation periodically: registering the tenant starts it, every
resourceUsageTransportPublishIntervalInSecs on the time scale the test passes. The test sets the interval to 300
and passes TimeUnit.MILLISECONDS, so the service aggregates every 300 ms. Since #24859 its first run comes 300 ms
after the registration, about when the test aggregates on a slow runner (10 sends, a close, Awaitility's 100 ms poll
delay). updateStatsWithDiff reads a topic's last counts, adds the difference to the group and then stores the new
counts. When the two aggregations overlap, both read the same last counts, and both add the same 10 messages.

In production the aggregation only runs from its one fixed-rate task, never concurrently with itself.

The retry then failed at resourceGroupCreate (Resource group already exists: runProduceConsume): the failed
attempt left its resource group behind. This PR doesn't make the test re-runnable after a failed attempt.

Modifications

Test code only: build the service on the SECONDS time scale, as RGUsageMTAggrWaitForAllMsgsTest does. Its own
aggregation then first runs 300 s after the registration, and each sub-run unregisters, which stops it, long before
that. The test's calls are the only aggregation:

// The test aggregates the usage itself: in seconds, the service's own aggregation first runs
// PUBLISH_INTERVAL_SECS after the tenant registration, after the test. Running concurrently with
// the test's, it would count the same messages twice.
this.rgs = new ResourceGroupService(pulsar, TimeUnit.SECONDS, transportMgr, dummyQuotaCalc);

Verifying this change

  • Make sure that the change passes the CI checks.

This change is covered by the test it changes.

To reproduce, widen the window between reading and storing a topic's counts (not committed): the test's service
overrides incrementUsage to sleep 250 ms first.

  • master: fails 2 of 2 runs with the CI error, at the same lines. A trace shows the test thread and a broker executor
    thread (the periodic task) each adding the 10 published messages, then the 10 dispatched ones. The retry fails with
    Resource group already exists, as on CI.
  • this PR: passes 2 of 2 runs; only the test thread adds usage.

Without the override, the test passes 4 of 4 runs locally, ~0.6 s as before. It is a rare flake: Develocity has 199
passes and no failure in the last 30 days, since the two aggregations must overlap on the same topic.

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 ResourceGroupUsageAggregationTest.testProduceCo…
0c2c413
…nsumeUsageOnRG

The test calls aggregateResourceGroupLocalUsages() itself, while the
ResourceGroupService it builds also runs it periodically. On the
MILLISECONDS time scale the 300 s publish interval is 300 ms, and since
apache#24859 the first periodic run comes 300 ms after the tenant
registration, about when the test aggregates on a slow runner. Both
read the topic's last counts before either stored the new ones, so both
added the same 10 messages: expected [20] but found [10].

Build the service on the SECONDS time scale, so that its own
aggregation doesn't run during the test.
@merlimat merlimat added the area/test label Nov 7, 2026
codelipenghui
codelipenghui approved these changes Nov 7, 2026
View reviewed changes
void-ptr974
void-ptr974 approved these changes Nov 7, 2026
View reviewed changes
@merlimat merlimat mentioned this pull request Nov 7, 2026
[fix][test] Fix flaky PendingAckInMemoryDeleteTest.txnAckTestBatchAndSharedSubMemoryDeleteTest #27453
Merged
11 tasks
@merlimat
merlimat merged commit 276a722 into apache:master Nov 7, 2026
119 of 123 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 ResourceGroupUsageAggregationTest.testProduceCo…
b6b47cf
…nsumeUsageOnRG (#27446)

(cherry picked from commit 276a722)
@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 ResourceGroupUsageAggregationTest.testProduceCo…
e39e203
…nsumeUsageOnRG (apache#27446)

(cherry picked from commit 276a722)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][test] Fix flaky ResourceGroupUsageAggregationTest.testProduceCo…
12c43fb
…nsumeUsageOnRG (apache#27446)

(cherry picked from commit 276a722)
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.