Merge #640's branch at its newest head into ci/process-level-tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-26 06:24:59 -08:00
commit 9602e2e6df
3 files changed
+58 -6

No files matched your search

@@ -40,17 +40,28 @@ func (env *handoffEnv) deleteSnapshot(t *testing.T, vol, name string) {
// control route (POST /chunk/snapshot/delete on hostID's status listener),
// which runs the holder's cleaning pass right after the delete. It returns
// the HTTP status and body.
//
// A snapshot delete is one conditional update of HEAD. The holder's
// cleaning (kicked by the previous delete) also updates HEAD, so a delete
// that read HEAD just before can lose its update ("HEAD generation moved")
// and change nothing; ops chunk snapshot-delete reports that as a retryable
// conflict. Only that answer is retried, within 30 s; any other is returned.
func (env *handoffEnv) holderDeleteSnapshot(t *testing.T, hostID, vol, name string) (int, string) {
t.Helper()
body, _ := json.Marshal(map[string]string{"volumeID": vol, "name": name})
c := &http.Client{Timeout: 2 * time.Minute}
resp, err := c.Post("http://"+env.hosts[hostID].status+"/chunk/snapshot/delete", "application/json", strings.NewReader(string(body)))
if err != nil {
t.Fatal(err)
for end := time.Now().Add(30 * time.Second); ; time.Sleep(200 * time.Millisecond) {
resp, err := c.Post("http://"+env.hosts[hostID].status+"/chunk/snapshot/delete", "application/json", strings.NewReader(string(body)))
if err != nil {
t.Fatal(err)
}
out, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
resp.Body.Close()
if resp.StatusCode == http.StatusOK || !strings.Contains(string(out), "HEAD generation moved") || time.Now().After(end) {
return resp.StatusCode, string(out)
}
t.Logf("holder delete of %s lost its HEAD update to a concurrent change; retrying: %s", name, out)
}
defer resp.Body.Close()
out, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
return resp.StatusCode, string(out)
}
// poolObjects counts the chunk objects in vol's pool (every shard
@@ -0,0 +1,22 @@
//go:build subprocess && chunkstore_integration
package main_test
import "testing"
// TestWeedPortPairsAvoidTheEphemeralRange: no port of a weed port pair lies in
// the host's range for outgoing connections' source ports, where any
// connection could take it between w4FreePortPair's free check and weed's bind
// (a filer's gRPC port inside a host's 43255-47350 failed to bind that way).
func TestWeedPortPairsAvoidTheEphemeralRange(t *testing.T) {
lo, hi := ephemeralPorts()
used := map[int]bool{}
for i := 0; i < 100; i++ {
p := w4FreePortPair(t, used)
for _, q := range []int{p, p + 10000} {
if q >= lo && q <= hi {
t.Fatalf("pair %d/%d: port %d is in the ephemeral range %d-%d", p, p+10000, q, lo, hi)
}
}
}
}
@@ -37,13 +37,32 @@ func testListenHost() string {
return "127.0.0.1"
}
// ephemeralPorts is the host's range for outgoing connections' source ports
// (Linux ip_local_port_range; the Linux default when unreadable). A port in it
// can be taken by any outgoing connection between the free check and weed's
// bind, so a port pair never uses it.
func ephemeralPorts() (int, int) {
lo, hi := 32768, 60999
if b, err := os.ReadFile("/proc/sys/net/ipv4/ip_local_port_range"); err == nil {
var a, z int
if n, _ := fmt.Sscan(string(b), &a, &z); n == 2 && a > 0 && z >= a {
lo, hi = a, z
}
}
return lo, hi
}
func w4FreePortPair(t *testing.T, used map[int]bool) int {
t.Helper()
lo, hi := ephemeralPorts()
for i := 0; i < 200; i++ {
p := 20000 + rand.Intn(20000)
if used[p] || used[p+10000] {
continue
}
if (p >= lo && p <= hi) || (p+10000 >= lo && p+10000 <= hi) {
continue
}
ok := true
for _, q := range []int{p, p + 10000} {
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", testListenHost(), q))