Skip to content

Commit 1201227

Browse files
committed
Improve test
1 parent 64abb9f commit 1201227

File tree

2 files changed

+19
-162
lines changed

2 files changed

+19
-162
lines changed

pulsar/consumer_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"time"
3434

3535
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/admin"
36+
"github.com/prometheus/client_golang/prometheus"
3637

3738
"github.com/stretchr/testify/require"
3839
"github.com/testcontainers/testcontainers-go"
@@ -5164,8 +5165,12 @@ func TestSelectConnectionForSameConsumer(t *testing.T) {
51645165
func TestAckIDListWillIncreaseAckCounterMetrics(t *testing.T) {
51655166
topicName := newTopicName()
51665167

5168+
// Create a custom metrics registry
5169+
registry := prometheus.NewRegistry()
5170+
51675171
client, err := NewClient(ClientOptions{
5168-
URL: serviceURL,
5172+
URL: serviceURL,
5173+
MetricsRegisterer: registry,
51695174
})
51705175
assert.NoError(t, err)
51715176
defer client.Close()
@@ -5200,7 +5205,18 @@ func TestAckIDListWillIncreaseAckCounterMetrics(t *testing.T) {
52005205
err = c.AckIDList(msgIDs)
52015206
assert.NoError(t, err)
52025207

5203-
ackCnt, err := getMetricValue("pulsar_client_consumer_acks")
5208+
// Get metrics directly from the registry
5209+
metrics, err := registry.Gather()
52045210
assert.NoError(t, err)
5205-
assert.Equal(t, float64(10), ackCnt)
5211+
5212+
var ackCount float64
5213+
for _, metric := range metrics {
5214+
if metric.GetName() == "pulsar_client_consumer_acks" {
5215+
for _, m := range metric.GetMetric() {
5216+
ackCount += m.GetCounter().GetValue()
5217+
}
5218+
}
5219+
}
5220+
5221+
assert.Equal(t, float64(10), ackCount)
52065222
}

pulsar/test_setup_test.go

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)