Repository navigation
[fix][test] Make admin and transaction tests tolerant of broker behavior changes - #1545
Conversation
…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]>
There was a problem hiding this comment.
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
TestSetTopicAutoCreationaccept 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
TestPartitionStateassertion 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.
- 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]>
There was a problem hiding this comment.
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
httpGetWithTLSusestime.Secondbuttimeis not imported in the updated import block shown in… · NewhttpGetWithTLSusestime.Secondbuttimeis not imported in the updated import block shown in… · New The new HTTPS test client has no timeout, so a stalled broker/network path can hang tests…httpGetWithTLSreloads the key pair, rereads the CA file, rebuilds the cert pool, and constructs… · New This direct type assertion (err.(rest.Error)) will panic ifSetTopicAutoCreationreturns a…
🧠 Review effort: Lite
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]>


Motivation
Releted PR: #1542
The
pulsar-client-goCI runs againstapachepulsar/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:
TestSetTopicAutoCreation— error-message changes:autoTopicCreationoverride 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.""Tenant does not exist"to"Namespace does not exist".TestTxn_TCClient— apache/pulsar#26773 ("Improve transaction admin checks", shipped in 4.2.5 and 5.0.0) addedvalidateSuperUserAccess()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 theanonymousrole and now rejects it with HTTP 401.TestPartitionState— apache/pulsar#26687 (PIP-379, shipped in 5.0.0 only) removedconsumersAfterMarkDeletePositionfrom the subscription stats. The broker no longer serializes the field, so it unmarshals tonilinstead of the empty map the test asserted.Modifications
TestSetTopicAutoCreation: replaced the single exact-matcherrReason stringfield with anerrReasons []stringslice and changed the assertion fromassert.Equaltoassert.Contains, listing both the old and the new broker strings.TestTxn_TCClient: added anhttpGetWithTLShelper (TLS web service + test client certificate, whose CNadminis insuperUserRoles) and used it fortransactionStats, so the super-user-only endpoint is called with a super-user identity.TestPartitionState: assertassert.Empty(...)forconsumersAfterMarkDeletePosition, 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.shin-container withPULSAR_VERSION=latest, broker and tests in the same container). Results against real broker versions:latest)TestSetTopicAutoCreationTestTxn_TCClientTestPartitionStateThe 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.