From 21969dc89e6b91b0dc4996b7404a15cc4aab679a Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 24 Dec 2025 20:06:52 -0800 Subject: [PATCH] testutil: use dynamic ports for master/volume/filer/metrics to avoid conflicts --- test/s3/testutil/server.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/test/s3/testutil/server.go b/test/s3/testutil/server.go index d51e5e004..7e196d4a1 100644 --- a/test/s3/testutil/server.go +++ b/test/s3/testutil/server.go @@ -74,17 +74,34 @@ func StartServer(config ServerConfig) (*TestServer, error) { "-volume.preStopSeconds=1", } - // 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 + // choose free ports for master, volume, filer and metrics to avoid collisions + pick := func() int { + l, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + return 0 + } + p := l.Addr().(*net.TCPAddr).Port l.Close() - } else { - metricsPort = 9324 + return p } - args = append(args, fmt.Sprintf("-metricsPort=%d", metricsPort)) + masterPort := pick() + volumePort := pick() + filerPort := pick() + metricsPort := pick() + + if masterPort != 0 { + args = append(args, fmt.Sprintf("-master.port=%d", masterPort)) + } + if volumePort != 0 { + args = append(args, fmt.Sprintf("-volume.port=%d", volumePort)) + } + if filerPort != 0 { + args = append(args, fmt.Sprintf("-filer.port=%d", filerPort)) + } + if metricsPort != 0 { + args = append(args, fmt.Sprintf("-metricsPort=%d", metricsPort)) + } if config.S3Config != "" { args = append(args, fmt.Sprintf("-s3.config=%s", config.S3Config))