KAFKA-20372: Fix flaky test in NamedTopologyIntegrationTest#21968
Open
chickenchickenlove wants to merge 1 commit intoapache:trunkfrom
Open
KAFKA-20372: Fix flaky test in NamedTopologyIntegrationTest#21968chickenchickenlove wants to merge 1 commit intoapache:trunkfrom
chickenchickenlove wants to merge 1 commit intoapache:trunkfrom
Conversation
Contributor
Author
|
@lianetm Hi! |
1dfc553 to
5dc9b00
Compare
Contributor
Author
|
@lianetm |
lianetm
reviewed
Apr 10, 2026
Member
lianetm
left a comment
There was a problem hiding this comment.
Thanks for looking into this!
| } | ||
| } | ||
|
|
||
| return true; |
Member
There was a problem hiding this comment.
if there are no tasks, this allTasksRunning would still return true, which is ok in the current test usage, but I wonder if it may be confusing. Should we add a java doc to call out the behaviour?
|
|
||
| TestUtils.waitForCondition( | ||
| () -> streams.allLocalTasksRunningForTopology(TOPOLOGY_1), | ||
| "topology tasks are still transitioning before remove" |
Member
There was a problem hiding this comment.
nit: seems clearer if we excplititly mention the final state that we didn't get to (~ tasks did not transition to running state as expected)
|
|
||
| TestUtils.waitForCondition( | ||
| () -> !streams.hasAnyLocalTaskForTopology(TOPOLOGY_1), | ||
| "topology tasks still exist internally after remove" |
Member
There was a problem hiding this comment.
nit
Suggested change
| "topology tasks still exist internally after remove" | |
| "tasks still exist internally after topology removed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR fixes a flaky test in
NamedTopologyIntegrationTest:shouldAddToEmptyInitialTopologyRemoveResetOffsetsThenAddSameNamedTopologyWithRepartitioning.The failure is caused by a race in the task lifecycle during named
topology removal.
In some runs, local tasks for the topology move to active/running
quickly. In other runs, some tasks can remain in a transitional state
for a short time, such as state update / restore, before becoming fully
active.
The test currently removes and cleans up the topology without waiting
for this lifecycle to settle. Because of that,
removeNamedTopology(...)may run while some local tasks are stilltransitioning, and
cleanUpNamedTopology(...)may follow before thosetasks are fully gone. This makes the subsequent re-add flow
non-deterministic and leads to intermittent failures.
To make the test deterministic, this PR adds explicit waits around the
remove / cleanup sequence:
removeNamedTopology(...)cleanUpNamedTopology(...)This keeps the test semantics unchanged and only stabilizes task
lifecycle timing in the test.
Test result in my local
Considered Alternatives
This would make it more likely that both partition 0 and partition 1
tasks are initialized before removal.
However, this changes the test input and can also introduce additional
rebalance and task-transition timing effects, since partition 1
processing becomes part of the exercised path. In other words, it may
reduce one symptom while introducing a different concurrency surface
related to task initialization and reassignment.
More importantly, the root cause of the flake is that the test does not
wait for task lifecycle transitions to settle before calling
removeNamedTopology(...)andcleanUpNamedTopology(...). Adding moreinput does not address that directly.
This would avoid the multi-partition timing issue by construction.
However, this also weakens the coverage of the test by removing the
multi-partition setup entirely. Since the production code supports
multiple partitions, reducing the topic to a single partition would hide
the race instead of synchronizing with the intended lifecycle of the
test.
Reviewers: Lianet Magrans 98415067+lianetm@users.noreply.github.com