You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "crossoverJie (via GitHub)" <gi...@apache.org> on 2026/10/15 06:10:54 UTC
[PR] [fix][test] Make TestSetTopicAutoCreation tolerant of broker error message changes [pulsar-client-go]
crossoverJie opened a new pull request, #1545:
URL: https://github.com/apache/pulsar-client-go/pull/1545
### Motivation
`TestSetTopicAutoCreation` (in `pulsaradmin/pkg/admin`) asserted the broker's *exact* error strings. This made the test brittle and it started failing once the broker changed those messages:
- [apache/pulsar#25163](https://github.com/apache/pulsar/pull/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"`.
Since the `pulsar-client-go` CI runs against `apachepulsar/pulsar:latest`, these tests now fail on `latest` (5.0.0) and on 4.2.5.
### Modifications
- Replaced the single exact-match `errReason string` field with an `errReasons []string` slice and changed the assertion from `assert.Equal` to `assert.Contains`.
- The two affected cases now list both the old and new broker error strings, so the test passes against both old and new broker versions instead of being coupled to broker wording.
### Verification
Verified against Pulsar **4.2.4** (old strings), **4.2.5** (new non-partition string) and **5.0.0** (`latest`, both new strings) — `TestSetTopicAutoCreation` passes on all three.
### Notes
`TestPartitionState` and `TestTxn_TCClient` are intentionally out of scope: their failures are environment/topology artifacts (host-vs-container networking / TLS cert trust) rather than broker error-message changes.
Co-Authored-By: CodeBuddy Code <no...@codebuddy.ai>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix][test] Make admin and transaction tests tolerant of broker behavior changes [pulsar-client-go]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1545:
URL: https://github.com/apache/pulsar-client-go/pull/1545#discussion_r4281048742
##########
pulsar/helper_for_test.go:
##########
@@ -157,13 +160,65 @@ func topicStats(topic string) (map[string]interface{}, error) {
return metadata, err
}
+// transactionStats queries the transaction metadata admin endpoint. Since
+// apache/pulsar#26773 that endpoint requires super-user access, so the request must be
+// authenticated. The plain-text httpGet helper sends no credentials and would be rejected
+// as the "anonymous" role (HTTP 401), so use the TLS web service with the test client
+// certificate instead, whose CN ("admin") is a super-user role in standalone.conf.
func transactionStats(id *TxnID) (map[string]interface{}, error) {
var metadata map[string]interface{}
path := fmt.Sprintf("admin/v3/transactions/transactionMetadata/%d/%d", id.MostSigBits, id.LeastSigBits)
- err := httpGet(path, &metadata)
+ err := httpGetWithTLS(path, &metadata)
return metadata, err
}
+// httpGetWithTLS performs an HTTPS GET against the broker's web service, authenticating
+// with the test client certificate. It is used for admin endpoints that require a
+// super-user role.
+func httpGetWithTLS(requestPath string, out interface{}) error {
+ cert, err := tls.LoadX509KeyPair(tlsClientCertPath, tlsClientKeyPath)
+ if err != nil {
+ return err
+ }
+ caCert, err := os.ReadFile(caCertsPath)
+ if err != nil {
+ return err
+ }
+ pool := x509.NewCertPool()
+ if !pool.AppendCertsFromPEM(caCert) {
+ return fmt.Errorf("failed to parse CA certificates from %s", caCertsPath)
+ }
+ client := &http.Client{
+ Transport: &http.Transport{
+ TLSClientConfig: &tls.Config{
+ Certificates: []tls.Certificate{cert},
+ RootCAs: pool,
+ },
+ },
+ }
Review Comment:
The new HTTPS test client has no timeout, so a stalled broker/network path can hang tests indefinitely. Set a reasonable `http.Client.Timeout` (and optionally transport-level timeouts) to bound test runtime and prevent CI deadlocks.
##########
pulsaradmin/pkg/admin/namespace_test.go:
##########
@@ -237,23 +241,23 @@ func TestSetTopicAutoCreation(t *testing.T) {
Allow: true,
Type: utils.NonPartitioned,
},
- errReason: "Tenant does not exist",
+ errReasons: []string{"Tenant does not exist", "Namespace does not exist"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
namespace, _ := utils.GetNamespaceName(tt.namespace)
err := admin.Namespaces().SetTopicAutoCreation(*namespace, tt.config)
- if tt.errReason == "" {
- assert.Equal(t, nil, err)
+ if len(tt.errReasons) == 0 {
+ assert.NoError(t, err)
err = admin.Namespaces().RemoveTopicAutoCreation(*namespace)
- assert.Equal(t, nil, err)
- }
- if err != nil {
- restError := err.(rest.Error)
- assert.Equal(t, tt.errReason, restError.Reason)
+ assert.NoError(t, err)
+ return
}
+ require.Error(t, err)
+ restError := err.(rest.Error)
+ assert.Contains(t, tt.errReasons, restError.Reason)
Review Comment:
This direct type assertion (`err.(rest.Error)`) will panic if `SetTopicAutoCreation` returns a non-`rest.Error` (e.g., transport errors, timeouts, TLS errors). Use `errors.As` (or a checked assertion) to safely extract the `rest.Error`, and fail the test with a clear message if the error isn’t of that type.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix][test] Make admin and transaction tests tolerant of broker behavior changes [pulsar-client-go]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1545:
URL: https://github.com/apache/pulsar-client-go/pull/1545#discussion_r4281596983
##########
pulsar/helper_for_test.go:
##########
@@ -19,10 +19,13 @@ package pulsar
import (
"bytes"
+ "crypto/tls"
+ "crypto/x509"
"encoding/json"
"fmt"
"io"
"net/http"
+ "os"
"path"
"strings"
"testing"
Review Comment:
`httpGetWithTLS` uses `time.Second` but `time` is not imported in the updated import block shown in this diff, which will fail compilation. Add `time` to the imports (or reuse an existing time import if the file already had one outside this hunk)."
##########
pulsar/helper_for_test.go:
##########
@@ -157,13 +160,66 @@ func topicStats(topic string) (map[string]interface{}, error) {
return metadata, err
}
+// transactionStats queries the transaction metadata admin endpoint. Since
+// apache/pulsar#26773 that endpoint requires super-user access, so the request must be
+// authenticated. The plain-text httpGet helper sends no credentials and would be rejected
+// as the "anonymous" role (HTTP 401), so use the TLS web service with the test client
+// certificate instead, whose CN ("admin") is a super-user role in standalone.conf.
func transactionStats(id *TxnID) (map[string]interface{}, error) {
var metadata map[string]interface{}
path := fmt.Sprintf("admin/v3/transactions/transactionMetadata/%d/%d", id.MostSigBits, id.LeastSigBits)
- err := httpGet(path, &metadata)
+ err := httpGetWithTLS(path, &metadata)
return metadata, err
}
+// httpGetWithTLS performs an HTTPS GET against the broker's web service, authenticating
+// with the test client certificate. It is used for admin endpoints that require a
+// super-user role.
+func httpGetWithTLS(requestPath string, out interface{}) error {
+ cert, err := tls.LoadX509KeyPair(tlsClientCertPath, tlsClientKeyPath)
+ if err != nil {
+ return err
+ }
+ caCert, err := os.ReadFile(caCertsPath)
+ if err != nil {
+ return err
+ }
+ pool := x509.NewCertPool()
+ if !pool.AppendCertsFromPEM(caCert) {
+ return fmt.Errorf("failed to parse CA certificates from %s", caCertsPath)
+ }
+ client := &http.Client{
+ Timeout: 30 * time.Second,
Review Comment:
`httpGetWithTLS` uses `time.Second` but `time` is not imported in the updated import block shown in this diff, which will fail compilation. Add `time` to the imports (or reuse an existing time import if the file already had one outside this hunk)."
##########
pulsar/helper_for_test.go:
##########
@@ -157,13 +160,66 @@ func topicStats(topic string) (map[string]interface{}, error) {
return metadata, err
}
+// transactionStats queries the transaction metadata admin endpoint. Since
+// apache/pulsar#26773 that endpoint requires super-user access, so the request must be
+// authenticated. The plain-text httpGet helper sends no credentials and would be rejected
+// as the "anonymous" role (HTTP 401), so use the TLS web service with the test client
+// certificate instead, whose CN ("admin") is a super-user role in standalone.conf.
func transactionStats(id *TxnID) (map[string]interface{}, error) {
var metadata map[string]interface{}
path := fmt.Sprintf("admin/v3/transactions/transactionMetadata/%d/%d", id.MostSigBits, id.LeastSigBits)
- err := httpGet(path, &metadata)
+ err := httpGetWithTLS(path, &metadata)
return metadata, err
}
+// httpGetWithTLS performs an HTTPS GET against the broker's web service, authenticating
+// with the test client certificate. It is used for admin endpoints that require a
+// super-user role.
+func httpGetWithTLS(requestPath string, out interface{}) error {
+ cert, err := tls.LoadX509KeyPair(tlsClientCertPath, tlsClientKeyPath)
+ if err != nil {
+ return err
+ }
+ caCert, err := os.ReadFile(caCertsPath)
+ if err != nil {
+ return err
+ }
+ pool := x509.NewCertPool()
+ if !pool.AppendCertsFromPEM(caCert) {
+ return fmt.Errorf("failed to parse CA certificates from %s", caCertsPath)
+ }
+ client := &http.Client{
+ Timeout: 30 * time.Second,
+ Transport: &http.Transport{
+ TLSClientConfig: &tls.Config{
+ Certificates: []tls.Certificate{cert},
+ RootCAs: pool,
+ },
+ },
+ }
Review Comment:
`httpGetWithTLS` reloads the key pair, rereads the CA file, rebuilds the cert pool, and constructs a new `http.Client` on every call. If this endpoint is queried multiple times across the test suite, this adds avoidable overhead. Consider caching the configured client (and cert pool) once (e.g., via `sync.Once`) and reusing it across calls.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix][test] Make admin and transaction tests tolerant of broker behavior changes [pulsar-client-go]
Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece merged PR #1545:
URL: https://github.com/apache/pulsar-client-go/pull/1545
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org