Skip to content

[fix][test] Make admin and transaction tests tolerant of broker behavior changes - #1545

Merged
nodece merged 5 commits into
apache:masterfrom
crossoverJie:fix/admin-test-version-tolerant-error-strings
Oct 20, 2026
Merged

nodece merged 5 commits into
apache:masterfrom
crossoverJie:fix/admin-test-version-tolerant-error-strings

Conversation

@crossoverJie

@crossoverJie crossoverJie commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Motivation

Releted PR: #1542

The pulsar-client-go CI runs against apachepulsar/pulsar:latest, which flipped to 5.0.0 on 2026-10-05 (4.2.5 and 5.0.0 were published the same day). Several tests assert specific 4.x broker behavior, so they turned red. This PR makes them tolerant of both the old and the new behavior.

Three distinct broker changes are involved:

  1. TestSetTopicAutoCreation — error-message changes:

    • apache/pulsar#25163 (shipped in 4.2.5) relaxed the non-partitioned autoTopicCreation override validation and changed the rejection text from
      "[defaultNumPartitions] is not allowed to be set when the type is non-partition."
      to
      "[defaultNumPartitions] must be null, 0 or 1 when the type is non-partitioned."
    • 5.0.0 changed the missing-tenant error from "Tenant does not exist" to "Namespace does not exist".
  2. TestTxn_TCClient — apache/pulsar#26773 ("Improve transaction admin checks", shipped in 4.2.5 and 5.0.0) added validateSuperUserAccess() to the transaction metadata admin endpoint (GET /admin/v3/transactions/transactionMetadata/{mostSigBits}/{leastSigBits}). The test read that endpoint through the raw admin HTTP helper, which calls the plain-text web service without credentials, so the broker treats the request as the anonymous role and now rejects it with HTTP 401.

  3. TestPartitionState — apache/pulsar#26687 (PIP-379, shipped in 5.0.0 only) removed consumersAfterMarkDeletePosition from the subscription stats. The broker no longer serializes the field, so it unmarshals to nil instead of the empty map the test asserted.

Modifications

  • TestSetTopicAutoCreation: replaced the single exact-match errReason string field with an errReasons []string slice and changed the assertion from assert.Equal to assert.Contains, listing both the old and the new broker strings.
  • TestTxn_TCClient: added an httpGetWithTLS helper (TLS web service + test client certificate, whose CN admin is in superUserRoles) and used it for transactionStats, so the super-user-only endpoint is called with a super-user identity.
  • TestPartitionState: assert assert.Empty(...) for consumersAfterMarkDeletePosition, which holds whether the field is absent/nil (5.0) or an empty map (4.x).

Verification

Ran the CI path (make test_standalone: docker build + scripts/run-ci.sh in-container with PULSAR_VERSION=latest, broker and tests in the same container). Results against real broker versions:

Test 4.2.4 4.2.5 5.0.0 (latest)
TestSetTopicAutoCreation ✅ ✅ ✅
TestTxn_TCClient ✅ ✅ ✅
TestPartitionState ✅ ✅ ✅

The full TestTxn_* suite (11 tests) also passes on 5.0.0.

Notes

These failures are genuine broker behavior changes, not environment/topology artifacts — verified by running the broker and the tests in the same container across 4.2.4 / 4.2.5 / 5.0.0.

crossoverJie and others added 3 commits October 15, 2026 14:09
…ssage changes

The test asserted exact broker error strings, which broke when Pulsar
changed the messages:

- apache/pulsar#25163 (shipped in 4.2.5) relaxed the non-partitioned
  autoTopicCreation override validation and changed the rejection text from
  "[defaultNumPartitions] is not allowed to be set when the type is
  non-partition." to "[defaultNumPartitions] must be null, 0 or 1 when the
  type is non-partitioned."
- 5.0.0 changed the missing-tenant error from "Tenant does not exist" to
  "Namespace does not exist".

Replace the single exact-match `errReason` with an `errReasons` slice and
assert containment, so the test passes against both old and new broker
versions instead of being brittle to broker wording changes.

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>
TestTxn_TCClient read transaction metadata through the raw admin HTTP helper
(httpGet -> httpDo), which calls the plain-text web service without any
credentials, so the broker authenticates it as the "anonymous" role.

apache/pulsar#26773 ("Improve transaction admin checks", shipped in 4.2.5 and
5.0.0) added validateSuperUserAccess() to the transaction metadata admin
endpoint (GET /admin/v3/transactions/transactionMetadata/{mostSigBits}/{leastSigBits}).
The unauthenticated request is now rejected with HTTP 401, so transactionStats
fails and the test panics on the nil stats map.

Add an httpGetWithTLS helper that calls the TLS web service using the test
client certificate, whose CN ("admin") is a super-user role in standalone.conf,
and use it for the transaction metadata request.

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>
apache/pulsar#26687 (PIP-379: Remove the classic Shared and Key_Shared
dispatcher implementations, shipped in 5.0.0) removed
consumersAfterMarkDeletePosition from the subscription stats. The broker no
longer serializes the field, so it unmarshals to a nil map instead of the
empty map the test asserted.

Assert the map is empty, which holds both for the old behavior (empty map)
and the new one (absent/nil).

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>
@crossoverJie crossoverJie changed the title [fix][test] Make TestSetTopicAutoCreation tolerant of broker error message changes [fix][test] Make admin and transaction tests tolerant of 4.2.5 / 5.0.0 broker changes Oct 15, 2026
@crossoverJie crossoverJie changed the title [fix][test] Make admin and transaction tests tolerant of 4.2.5 / 5.0.0 broker changes [fix][test] Make admin and transaction tests tolerant of broker behavior changes Oct 15, 2026
@crossoverJie
crossoverJie requested review from wolfstudy and a balanced review from Copilot October 15, 2026 08:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open findings
What changed in this PR

Updates test suite and test helpers to tolerate behavior changes introduced in newer Pulsar brokers (4.2.5 / 5.0.0), keeping CI green when running against apachepulsar/pulsar:latest.

Changes:

  • Make TestSetTopicAutoCreation accept multiple broker error messages instead of exact-matching a single string.
  • Authenticate the transaction metadata admin endpoint call by adding an HTTPS+client-cert test helper.
  • Relax TestPartitionState assertion to accept both “field absent” (nil) and “empty map” representations.
File Description
pulsaradmin/​pkg/​admin/​topic_test.go Adjusts assertion to tolerate removed/omitted subscription-stats field in Pulsar 5.0.
pulsaradmin/​pkg/​admin/​namespace_test.go Generalizes test expectations to accept multiple valid error reasons across broker versions.
pulsar/​helper_for_test.go Adds TLS-authenticated GET helper and uses it for transaction metadata stats endpoint.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pulsar/helper_for_test.go Resolved
Comment thread pulsaradmin/pkg/admin/namespace_test.go Resolved
- httpGetWithTLS: give the HTTPS test client a 30s timeout so a stalled
  broker/network path cannot hang the test run.
- TestSetTopicAutoCreation: replace the unchecked `err.(rest.Error)` type
  assertion (which panics on transport/TLS errors) with `require.ErrorAs`.

Co-Authored-By: CodeBuddy Code <[email protected]>
@crossoverJie
crossoverJie requested a balanced review from Copilot October 15, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

5 open findings

🧠 Review effort: Lite

Comment thread pulsar/helper_for_test.go Resolved
Comment thread pulsar/helper_for_test.go Resolved
Comment thread pulsar/helper_for_test.go Resolved
Build the HTTPS client (key pair, CA pool) once via sync.Once and reuse it
across calls instead of rebuilding it on every request.

Co-Authored-By: CodeBuddy Code <[email protected]>
@nodece
nodece merged commit e3619f3 into apache:master Oct 20, 2026
7 checks passed
@crossoverJie
crossoverJie deleted the fix/admin-test-version-tolerant-error-strings branch October 20, 2026 04:05
@nodece nodece added this to the 0.22.0 milestone Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants