From eb471459de2ea7bf645fe6137f239836a18aba70 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 24 Nov 2026 13:29:39 -0800 Subject: [PATCH] test: keep the NVMe/TCP listener on loopback when the harness listens off loopback blockvolume refuses a non-loopback frontend listen; the test reaches its NVMe target only from the same host (user-space client or kernel nvme connect), so the NVMe address stays 127.0.0.1 (headSzLoopbackAddr) while data and ctrl use SWBLOCK_TEST_LISTEN_HOST. Co-Authored-By: Claude Fable 5.1 --- .../blockvolume/head_size_integration_test.go | 30 ++++++++++++++++++- .../known_zero_acceptance_integration_test.go | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/head_size_integration_test.go b/seaweed-block/cmd/blockvolume/head_size_integration_test.go index a79cb99845..bd1328fb71 100644 --- a/seaweed-block/cmd/blockvolume/head_size_integration_test.go +++ b/seaweed-block/cmd/blockvolume/head_size_integration_test.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "math/rand" + "net" "net/http" "net/url" "os" @@ -217,7 +218,7 @@ func headSzStartCluster(t *testing.T, prefix string, vols []headSzVol) (*handoff server, replica = v.server, "r1" } b := bvHost{id: v.id, server: server, replica: replica, volume: v.id, root: filepath.Join(h.dir, "vol-"+v.id), - data: handoffAddress(t), ctrl: handoffAddress(t), status: handoffAddress(t), nvme: handoffAddress(t)} + data: handoffAddress(t), ctrl: handoffAddress(t), status: handoffAddress(t), nvme: headSzLoopbackAddr(t)} if v.host != "" { b.data, b.ctrl = headSzRemoteAddr(t, v.host), headSzRemoteAddr(t, v.host) } @@ -244,6 +245,33 @@ func headSzStartCluster(t *testing.T, prefix string, vols []headSzVol) (*handoff return env, clusterDir } +// headSzLoopbackAddr picks a free 127.0.0.1 port from the harness's range: +// blockvolume's NVMe/TCP target refuses any non-loopback bind, and the test +// (user-space client or kernel nvme connect) always runs on the same host as +// that blockvolume, also when SWBLOCK_TEST_LISTEN_HOST names a host address. +func headSzLoopbackAddr(t *testing.T) string { + t.Helper() + handoffPorts.Lock() + defer handoffPorts.Unlock() + if handoffPorts.used == nil { + handoffPorts.used = map[int]bool{} + } + for i := 0; i < 500; i++ { + p := 10000 + rand.Intn(10000) + if handoffPorts.used[p] { + continue + } + addr := fmt.Sprintf("127.0.0.1:%d", p) + if ln, err := net.Listen("tcp", addr); err == nil { + ln.Close() + handoffPorts.used[p] = true + return addr + } + } + t.Fatal("no free loopback port") + return "" +} + // headSzRemoteAddr picks host: for a process on another machine from // the same port range handoffAddress uses, never handing out a port twice. func headSzRemoteAddr(t *testing.T, host string) string { diff --git a/seaweed-block/cmd/blockvolume/known_zero_acceptance_integration_test.go b/seaweed-block/cmd/blockvolume/known_zero_acceptance_integration_test.go index 55726f1dfb..adbf21c21b 100644 --- a/seaweed-block/cmd/blockvolume/known_zero_acceptance_integration_test.go +++ b/seaweed-block/cmd/blockvolume/known_zero_acceptance_integration_test.go @@ -244,7 +244,7 @@ func kzTargetRole(t *testing.T, rep *kzReport, bytes uint64, device bool, run st rep.ChunkPath = ho.ChunkPath for _, ht := range ho.Targets { tb := bvHost{id: ht.Volume, server: ht.Server, replica: "r1", volume: ht.Volume, root: filepath.Join(h.dir, "vol-"+ht.Volume), - data: ht.Data, ctrl: ht.Ctrl, status: handoffAddress(t), nvme: handoffAddress(t)} + data: ht.Data, ctrl: ht.Ctrl, status: handoffAddress(t), nvme: headSzLoopbackAddr(t)} env.hosts[ht.Volume] = tb src := kzVolume{Volume: ht.Source, S1Name: ht.S1, Dirty1: ht.Dirty1, Files: ht.Files, Blocks: map[uint64][]byte{}} for k, v := range ht.Blocks {