Skip to content

Conversation

@pdolif
Copy link
Contributor

@pdolif pdolif commented Oct 14, 2025

Fixes #24837

Motivation

The test is flaky. It verifies that lookup requests use the lookup properties configured at the time when the request is triggered (and not at the time it is executed).
Therefore, it triggers 10 broker lookups in sequence and changes the lookup properties before each. The property "broker.id" is set to "key-0", "key-1",..., "key-9" respectively. To verify that the correct properties are used, the test uses the BrokerIdAwareLoadManager, which extends ExtensibleLoadManagerImpl. It stores a CLIENT_ID_LIST. When assign() is called, the "broker.id" property is added to the CLIENT_ID_LIST.
The test waits until all lookup requests finish, and then asserts that CLIENT_ID_LIST is equal to "key-0", "key-1",..., "key-9". The assertion fails if the list contains the values in a different order.

When running the tests, I noticed that the order is either "key-0", "key-1",..., "key-9" (ascending) or the reverse order. The reason seems to be related to CompletableFuture "callbacks" like thenCompose() and their execution order. For example, for each of the 10 lookup requests, NamespaceService.getBrokerServiceUrlAsync() is called (in sequence), which contains the following code:

CompletableFuture<Optional<LookupResult>> future = getBundleAsync(topic)
.thenCompose(bundle -> {

When thenCompose() is called, it can either be that the getBundleAsync(topic) CompletableFuture is completed or not. If it is completed, thenCompose() can be executed immediately for each of the 10 lookup requests. The test passes. If it is not completed, thenCompose() is called 10 times but not executed immediately. It seems like the "callbacks" are stacked. Once the CompletableFuture completes, the 10 "callbacks" are executed in LIFO order, i.e., the one for "key-9" is executed first. Therefore, the order in CLIENT_ID_LIST will be reversed, and the test fails.

Modifications

Make the assertion less strict and ignore the value order.

Verifying this change

  • Make sure that the change passes the CI checks.

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

Documentation

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

Matching PR in forked repository

PR in forked repository: pdolif#17

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Oct 14, 2025
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.

Great analysis. Thanks for fixing!

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.32%. Comparing base (461ffd8) to head (aeecb8c).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #24854      +/-   ##
============================================
- Coverage     74.36%   74.32%   -0.04%     
+ Complexity    33856    33481     -375     
============================================
  Files          1913     1913              
  Lines        149280   149280              
  Branches      17324    17324              
============================================
- Hits         111012   110957      -55     
- Misses        29445    29490      +45     
- Partials       8823     8833      +10     
Flag Coverage Δ
inttests 26.63% <ø> (-0.02%) ⬇️
systests 22.77% <ø> (-0.08%) ⬇️
unittests 73.86% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 102 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lhotari lhotari merged commit d743278 into apache:master Oct 15, 2025
98 of 100 checks passed
lhotari pushed a commit that referenced this pull request Oct 28, 2025
lhotari pushed a commit that referenced this pull request Oct 28, 2025
manas-ctds pushed a commit to datastax/pulsar that referenced this pull request Oct 29, 2025
…ties (apache#24854)

(cherry picked from commit d743278)
(cherry picked from commit 324fadd)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Nov 6, 2025
…ties (apache#24854)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky-test: LookupPropertiesTest.testConcurrentLookupProperties

4 participants