mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test(storage): distinguish warm attempts from measurement rounds
This commit is contained in:
1 parent
0141be5aaf
commit
68d8cabada
1 file changed
+33
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user