Skip to content

Commit 64abb9f

Browse files
committed
Address comments
1 parent 7518a07 commit 64abb9f

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

pulsar/consumer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5190,14 +5190,14 @@ func TestAckIDListWillIncreaseAckCounterMetrics(t *testing.T) {
51905190

51915191
assert.NoError(t, err)
51925192

5193-
msgIds := make([]MessageID, 10)
5193+
msgIDs := make([]MessageID, 10)
51945194
for i := 0; i < 10; i++ {
51955195
msg, err := c.Receive(context.Background())
51965196
assert.NoError(t, err)
5197-
msgIds[i] = msg.ID()
5197+
msgIDs[i] = msg.ID()
51985198
}
51995199

5200-
err = c.AckIDList(msgIds)
5200+
err = c.AckIDList(msgIDs)
52015201
assert.NoError(t, err)
52025202

52035203
ackCnt, err := getMetricValue("pulsar_client_consumer_acks")

pulsar/test_setup_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,19 @@ func startMetricsServer() error {
6868
}
6969
}()
7070

71-
// Wait a bit for server to start
72-
time.Sleep(100 * time.Millisecond)
71+
// Wait for server to start with a retry mechanism
72+
timeout := time.Now().Add(5 * time.Second)
73+
for {
74+
conn, err := net.Dial("tcp", addr)
75+
if err == nil {
76+
conn.Close()
77+
break
78+
}
79+
if time.Now().After(timeout) {
80+
return fmt.Errorf("server did not start within the timeout period: %v", err)
81+
}
82+
time.Sleep(50 * time.Millisecond)
83+
}
7384
return nil
7485
}
7586

@@ -105,7 +116,8 @@ func getMetricValue(metricName string) (float64, error) {
105116
if strings.HasPrefix(strings.TrimSpace(line), "#") {
106117
continue
107118
}
108-
if strings.Contains(line, metricName) {
119+
if strings.HasPrefix(line, metricName) && (len(line) == len(metricName) ||
120+
line[len(metricName)] == '{' || line[len(metricName)] == ' ') {
109121
// Parse the metric line to extract the value
110122
// Format: metric_name{label="value",label2="value2"} 10
111123
parts := strings.Fields(line)

0 commit comments

Comments
 (0)