From ff4bc9a0d7bf5ec5f2fca2fc7955cd0e9ac7f3a6 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 5 Dec 2026 14:51:37 -0800 Subject: [PATCH] test(block): claim the mini test's ports host-wide The pid-derived --port-shift put mini's 13 ports inside the handoff and weed pair ranges the other process-level harnesses claim, unclaimed, so a parallel CI shard could bind one of them. Pick a shift whose every port is claimed and free, as handoffAddress does. Co-Authored-By: Claude Opus 5.5 --- .../mini_nonroot_integration_test.go | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/seaweed-block/cmd/blockvolume/mini_nonroot_integration_test.go b/seaweed-block/cmd/blockvolume/mini_nonroot_integration_test.go index d46d84870e..e708452ba8 100644 --- a/seaweed-block/cmd/blockvolume/mini_nonroot_integration_test.go +++ b/seaweed-block/cmd/blockvolume/mini_nonroot_integration_test.go @@ -5,6 +5,8 @@ package main_test import ( "context" "fmt" + "math/rand" + "net" "os" "path/filepath" "strings" @@ -41,7 +43,7 @@ func TestMiniStartsWithoutRootAndNamesItsBinaries(t *testing.T) { t.Fatal(err) } cli := filepath.Join(bins, "sw-block") - shift := 3000 + (os.Getpid()*13)%6000 + shift := miniPortShift(t) dir := filepath.Join(t.TempDir(), "mini") ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute) defer cancel() @@ -131,6 +133,35 @@ func miniGoBuild(t *testing.T, out, pkg string) { } +// miniPortShift picks a --port-shift whose every mini port (defaultMiniPorts +// in cmd/sw-block) is claimed host-wide and free now, as the other harnesses' +// ports are, so a parallel process-level shard never binds one of them. +func miniPortShift(t *testing.T) int { + t.Helper() + defaults := []int{9180, 9201, 9202, 9203, 4420, 9333, 19333, 9340, 19340, 8888, 18888, 12535, 22535} + for i := 0; i < 200; i++ { + shift := 3000 + rand.Intn(6000) + free := true + for _, p := range defaults { + if !claimHostPort(p + shift) { + free = false + break + } + ln, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", p+shift)) + if err != nil { + free = false + break + } + ln.Close() + } + if free { + return shift + } + } + t.Fatal("no --port-shift with every mini port claimed and free") + return 0 +} + func exists(p string) bool { _, err := os.Stat(p) return err == nil