test(blockvolume): HEADSZ runs its snapshots past the shared 150 s bound

TEST V1-SPEC r2.99/r2.100: the shared sw-block runner kills a command after
150 s, so a cut longer than that never reached the server's own operation
deadline. HEADSZ now runs the snapshot command with its own bound, the
command's --timeout plus a minute, and records a command it still has to
kill as an attempt. It also records the volume's DirtyChunks (its capture
candidates) before the first cut.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Fable 5.1 committed 2026-11-23 16:59:53 -08:00
1 parent 7ec838451a
commit 0c44cbc29a
1 file changed
+72 -9
@@ -3,12 +3,15 @@
package main_test
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
@@ -69,14 +72,17 @@ type headSzCut struct {
}
type headSzSize struct {
Size string `json:"size"`
Bytes uint64 `json:"bytes"`
Segments int `json:"segments"`
Result string `json:"result"` // measured | refused_headroom | cut_not_completed
Refusal string `json:"refusal,omitempty"`
WriteMs float64 `json:"write_ms,omitempty"`
Cuts []headSzCut `json:"cuts,omitempty"`
HeadPerGiB float64 `json:"head_bytes_per_gib,omitempty"`
Size string `json:"size"`
Bytes uint64 `json:"bytes"`
Segments int `json:"segments"`
Result string `json:"result"` // measured | refused_headroom | cut_not_completed
Refusal string `json:"refusal,omitempty"`
WriteMs float64 `json:"write_ms,omitempty"`
// DirtyBeforeCut1 is the volume's DirtyChunks (its capture candidates)
// from the durable status right before the first cut.
DirtyBeforeCut1 int `json:"dirty_chunks_before_cut1"`
Cuts []headSzCut `json:"cuts,omitempty"`
HeadPerGiB float64 `json:"head_bytes_per_gib,omitempty"`
}
type headSzReport struct {
@@ -231,6 +237,7 @@ func headSzOne(t *testing.T, env *handoffEnv, cfg headSzConfig, size string, cha
_ = c.io.SetDeadline(time.Now().Add(60 * time.Second))
c.flush(t)
row.WriteMs = ms(time.Since(start))
row.DirtyBeforeCut1 = headSzDirty(t, b)
for cut := 1; cut <= 1+changeCuts; cut++ {
changed := 0
if cut > 1 {
@@ -264,7 +271,7 @@ func headSzCutOnce(t *testing.T, env *handoffEnv, cfg headSzConfig, b bvHost, cu
start := time.Now()
for a := 1; a <= cfg.attempts; a++ {
as := time.Now()
out, _, code := env.h.run(t, "ops", "chunk", "snapshot", "--volume", b.volume, "--status-addr", b.status, "--timeout", cfg.snapshotTimeout,
out, code := headSzRun(t, env, cfg.snapshotTimeout, "ops", "chunk", "snapshot", "--volume", b.volume, "--status-addr", b.status, "--timeout", cfg.snapshotTimeout,
"--name", fmt.Sprintf("headsz-%d", cut), "--request-id", fmt.Sprintf("headsz-%s-%d", b.volume, cut))
at := headSzAttempt{Attempt: a, ExitCode: code, WallMs: ms(time.Since(as)), KeysAfter: headSzCountDir(t, env, env.chunkPath+"/"+b.volume+"/keys")}
if code != 0 {
@@ -385,6 +392,62 @@ func headSzCountDir(t *testing.T, env *handoffEnv, dir string) int {
}
}
// headSzRun runs sw-block with its own bound, the snapshot command's
// --timeout plus a minute, so the server's operation deadline answers first
// (the shared runner's fixed 150 s would kill a longer cut). A command that
// still has to be killed returns exit code -1 and its output, a recorded
// attempt, never a test failure.
func headSzRun(t *testing.T, env *handoffEnv, timeout string, args ...string) (string, int) {
t.Helper()
d, err := time.ParseDuration(timeout)
if err != nil {
t.Fatalf("timeout %q: %v", timeout, err)
}
ctx, cancel := context.WithTimeout(context.Background(), d+time.Minute)
defer cancel()
cmd := exec.CommandContext(ctx, env.h.cli, args...)
cmd.Dir = env.h.dir
cmd.WaitDelay = 5 * time.Second
var stdout, stderr strings.Builder
cmd.Stdout, cmd.Stderr = &stdout, &stderr
err = cmd.Run()
env.h.logCommand(args, stdout.String(), stderr.String(), err)
var exit *exec.ExitError
switch {
case err == nil:
return stdout.String(), 0
case errors.As(err, &exit) && ctx.Err() == nil:
return stdout.String(), exit.ExitCode()
case ctx.Err() != nil:
return "killed after " + (d + time.Minute).String() + ": " + strings.TrimSpace(stdout.String()+" "+stderr.String()), -1
}
t.Fatalf("sw-block %q: %v\nstdout: %s\nstderr: %s", args, err, stdout.String(), stderr.String())
return "", -1
}
// headSzDirty reads the volume's DirtyChunks (its capture candidates) from
// its durable status; -1 when the status has no chunk section.
func headSzDirty(t *testing.T, b bvHost) int {
t.Helper()
var st struct {
Volumes []struct {
VolumeID string
Chunk *struct {
Stats struct{ DirtyChunks int }
}
}
}
if err := json.Unmarshal(headSzGet(t, "http://"+b.status+"/status/durable?volume="+b.volume, 4<<20), &st); err != nil {
t.Fatalf("durable status of %s: %v", b.volume, err)
}
for _, s := range st.Volumes {
if s.VolumeID == b.volume && s.Chunk != nil {
return s.Chunk.Stats.DirtyChunks
}
}
return -1
}
func headSzGet(t *testing.T, u string, limit int64) []byte {
t.Helper()
c := &http.Client{Timeout: 30 * time.Second}