[fix][test] Fix flaky LookupPropertiesTest.testConcurrentLookupProperties #24854
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.
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 extendsExtensibleLoadManagerImpl. It stores aCLIENT_ID_LIST. Whenassign()is called, the "broker.id" property is added to theCLIENT_ID_LIST.The test waits until all lookup requests finish, and then asserts that
CLIENT_ID_LISTis 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:pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
Lines 225 to 226 in 461ffd8
When
thenCompose()is called, it can either be that thegetBundleAsync(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 inCLIENT_ID_LISTwill be reversed, and the test fails.Modifications
Make the assertion less strict and ignore the value order.
Verifying this change
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: pdolif#17