diff --git a/seaweed-block/core/storage/chunk_precopy_detach_test.go b/seaweed-block/core/storage/chunk_precopy_detach_test.go index 74d07fef4a..07c1006ea7 100644 --- a/seaweed-block/core/storage/chunk_precopy_detach_test.go +++ b/seaweed-block/core/storage/chunk_precopy_detach_test.go @@ -3,6 +3,7 @@ package storage import ( "bytes" "context" + "encoding/json" "errors" "path/filepath" "testing" @@ -416,3 +417,35 @@ func TestPrecopyAttemptDiagnosticsSeparateTimeoutFromFit(t *testing.T) { } } } + +func TestPrecopyCountsWarmAttemptsSeparatelyFromMeasurementRounds(t *testing.T) { + for _, warm := range []bool{false, true} { + t.Run(map[bool]string{false: "cold", true: "warm"}[warm], func(t *testing.T) { + _, _, l, _ := precopyLayer(t, 1024, 0) + l.precopySamples = nil + if warm { + for i := 0; i < 3; i++ { + l.precopySamples = append(l.precopySamples, precopySample{at: time.Now(), fixed: time.Millisecond, rate: 1 << 30}) + } + } + r, _ := l.PrecopyDetachWithAdmission(ctTimeout(t), func(context.Context) (func(), error) { + return nil, errors.New("controlled admission refusal") + }, func() bool { t.Fatal("refused admission froze"); return false }) + data, err := json.Marshal(r.Precopy) + if err != nil { + t.Fatal(err) + } + var fields map[string]any + if err := json.Unmarshal(data, &fields); err != nil { + t.Fatal(err) + } + wantSamples, wantAttempts, wantMeasurement := float64(0), float64(0), float64(5) + if warm { + wantSamples, wantAttempts, wantMeasurement = 3, 5, 0 + } + if fields["samplesAtStart"] != wantSamples || fields["attempts"] != wantAttempts || fields["measurementRounds"] != wantMeasurement || len(r.Precopy.Rounds) != 5 { + t.Fatalf("warm=%t report=%s", warm, data) + } + }) + } +}