From 7dfa361e6e05c837813d8d89e7dfd7704767688c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 24 Dec 2025 20:06:08 -0800 Subject: [PATCH] testutil: pick dynamic metrics port to avoid bind conflicts in tests --- test/s3/testutil/server.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/s3/testutil/server.go b/test/s3/testutil/server.go index 269cc9ce4..d51e5e004 100644 --- a/test/s3/testutil/server.go +++ b/test/s3/testutil/server.go @@ -2,6 +2,7 @@ package testutil import ( "fmt" + "net" "net/http" "os" "os/exec" @@ -71,9 +72,20 @@ func StartServer(config ServerConfig) (*TestServer, error) { "-volume.max=100", fmt.Sprintf("-dir=%s", config.DataDir), "-volume.preStopSeconds=1", - "-metricsPort=9324", } + // choose a free metrics port to avoid collisions in parallel test runs + metricsPort := 0 + if l, err := net.Listen("tcp", "127.0.0.1:0"); err == nil { + addr := l.Addr().(*net.TCPAddr) + metricsPort = addr.Port + l.Close() + } else { + metricsPort = 9324 + } + + args = append(args, fmt.Sprintf("-metricsPort=%d", metricsPort)) + if config.S3Config != "" { args = append(args, fmt.Sprintf("-s3.config=%s", config.S3Config)) }