Skip to content

Commit 39a8629

Browse files
committed
Use IPv6 localhost for relay test
This is the only way I could find to make the test pass on _my_ macOS machine: ``` Darwin mr-6.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000 arm64 ``` I don't understand the problem here, and I am not sure what the implications are; this probably breaks the test on IPv4-only machines if those still exist. Without this change, or even when using 127.0.0.1, nothing is received. ``` === RUN TestRelay_RelayLine === RUN TestRelay_RelayLine/multiple_lines udp.go:85: At: /Users/mr/src/github.com/prometheus/statsd_exporter/pkg/relay/relay_test.go:68 udp.go:115: Expected to find: "foo5:100|c|#tag1:bar,#tag2:baz\n" udp.go:116: But got: "" --- FAIL: TestRelay_RelayLine (0.00s) --- FAIL: TestRelay_RelayLine/multiple_lines (0.00s) FAIL FAIL github.com/prometheus/statsd_exporter/pkg/relay 1.809s FAIL ``` Is there a better or more well understood solution? Possibly related: `localhost` is [not well defined](golang/go#22826). Signed-off-by: Matthias Rampke <matthias@prometheus.io>
1 parent 9115f0f commit 39a8629

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pkg/relay/relay_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ func TestRelay_RelayLine(t *testing.T) {
4545
},
4646
}
4747

48+
const testAddr = "[::1]:1160"
49+
4850
for _, tt := range tests {
49-
udp.SetAddr(":1160")
51+
udp.SetAddr(testAddr)
5052
t.Run(tt.name, func(t *testing.T) {
5153
tickerCh := make(chan time.Time)
5254
clock.ClockInstance = &clock.Clock{
@@ -57,7 +59,7 @@ func TestRelay_RelayLine(t *testing.T) {
5759
logger := log.NewNopLogger()
5860
r, err := NewRelay(
5961
logger,
60-
"localhost:1160",
62+
testAddr,
6163
200,
6264
)
6365

@@ -92,7 +94,7 @@ func TestRelay_RelayLine(t *testing.T) {
9294
"statsd_exporter_relay_lines_relayed_total": float64(len(tt.args.lines)),
9395
}
9496
for metricName, expectedValue := range metricNames {
95-
metric := getFloat64(metrics, metricName, prometheus.Labels{"target": "localhost:1160"})
97+
metric := getFloat64(metrics, metricName, prometheus.Labels{"target": testAddr})
9698

9799
if metric == nil {
98100
t.Fatalf("Could not find time series with first label set for metric: %s", metricName)

0 commit comments

Comments
 (0)