Repository navigation
[fix][test] Deflake TopicPoliciesTest.setupTestTopic by retrying forced namespace deletion - #25974
Merged
Merged
Conversation
…ed namespace deletion The @BeforeMethod setup force-deletes the namespace before each test. The forced deletion cascades through topic deletions, which can transiently fail with HTTP 422 (an IllegalStateException from a topic-delete racing with concurrent topic loading). The setup only caught NotFoundException, so the transient 422 failed the whole test. Use the existing MockedPulsarServiceBaseTest#deleteNamespaceWithRetry helper, which retries the deletion on transient errors and treats an already-deleted namespace as success. Assisted-by: Claude Code (Opus 4.8)
merlimat
approved these changes
Jun 8, 2026
lhotari
added a commit
that referenced
this pull request
Jun 10, 2026
…ed namespace deletion (#25974)
lhotari
added a commit
that referenced
this pull request
Jun 10, 2026
…ed namespace deletion (#25974)
priyanshu-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Jun 15, 2026
…ed namespace deletion (apache#25974) (cherry picked from commit 72e4d26)
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Aug 28, 2026
…ed namespace deletion (apache#25974)
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.
Motivation
TopicPoliciesTest.setupTestTopic(a@BeforeMethod) is flaky. It was observed failing in CI with:The setup recreates the namespace before each test by force-deleting it. A forced namespace
deletion cascades through
NamespacesBase#internalDeleteTopicsAsync, which deletes each topic viathe admin REST client. When a topic deletion races with concurrent topic loading, the broker raises
an
IllegalStateException, whichPersistentTopics#deleteTopicmaps to HTTP 422 (with an empty{}body when the exception message is null). The setup only caughtNotFoundException(404), sothis transient 422 escaped and failed the test.
The failure is transient: in the same CI run 483/484 tests passed, i.e. the identical setup ran
successfully many times — only one invocation hit the race.
Modifications
Replace the two raw
admin.namespaces().deleteNamespace(..., true)calls (each guarded only againstNotFoundException) with the existingMockedPulsarServiceBaseTest#deleteNamespaceWithRetry(ns, force)helper, which already exists for exactly this purpose ("maybe fail by race-condition with create
topics, just retry"): it retries the forced deletion on transient errors and treats an
already-deleted namespace as success. No assertions were weakened; the test intent (reset namespace
state before each test) is preserved.
Verifying this change
This change is already covered by existing tests, such as the whole
TopicPoliciesTestsuite. Thefix targets the
@BeforeMethodthat runs before every test in the class. Verified locally:TopicPoliciesTestruns green (114 tests, 0 failures/0 errors), sosetupTestTopicexecuted 114times successfully. Note that this is a timing-dependent race, so a clean local run is only weak
evidence; the fix is structural — it reuses the codebase's established retry helper for this exact
race condition.
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes