mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
test(storage): pin drain deadline and exclude late unadmitted writes
This commit is contained in:
1 parent
390f8fb32e
commit
7e31afeda1
2 files changed
+81
No files matched your search
@@ -71,3 +71,68 @@ func TestPrecopyAdmissionPauseBoundsDrainAndReopens(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrecopyLateGateCallerCannotCrossFreeze(t *testing.T) {
|
||||
remote := storage.NewMemChunkRemote()
|
||||
p, view := parkedProvider(t, remote)
|
||||
openRecovered(t, p)
|
||||
b, err := p.Open(context.Background(), "v1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gate := b.(interface {
|
||||
BeginPrecopyPause(context.Context) (func(), error)
|
||||
TryStopIO(string) bool
|
||||
})
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
view.arm()
|
||||
done := make(chan struct{})
|
||||
var writeErr error
|
||||
t.Cleanup(func() {
|
||||
view.unpark()
|
||||
cancel()
|
||||
_ = b.Close()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(time.Second):
|
||||
t.Error("late command did not join")
|
||||
}
|
||||
})
|
||||
go func() { defer close(done); _, writeErr = b.Write(ctx, 4096, block(0x5b)) }()
|
||||
select {
|
||||
case <-view.entered:
|
||||
case <-ctx.Done():
|
||||
t.Fatal("late gate not reached")
|
||||
}
|
||||
resume, err := gate.BeginPrecopyPause(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(resume)
|
||||
if !gate.TryStopIO("final pre-copy cut") {
|
||||
t.Fatal("drained pause failed to commit")
|
||||
}
|
||||
view.unpark()
|
||||
select {
|
||||
case <-done:
|
||||
t.Fatalf("late gate crossed frozen admission: %v", writeErr)
|
||||
case <-time.After(50 * time.Millisecond):
|
||||
}
|
||||
if _, err := p.CaptureVolume(ctx, "v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if headBlock(t, remote, 1)[0] != 0 {
|
||||
t.Fatal("unadmitted late write reached captured bytes")
|
||||
}
|
||||
if err := b.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
select {
|
||||
case <-done:
|
||||
if !errors.Is(writeErr, frontend.ErrBackendClosed) {
|
||||
t.Fatal(writeErr)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatal("closed path did not settle late command")
|
||||
}
|
||||
}
|
||||
@@ -335,3 +335,19 @@ func TestPrecopyDetachColdNoopRequiresMeasuredCASCost(t *testing.T) {
|
||||
t.Fatalf("measured CAS did not enable empty-tail freeze: report=%+v stopped=%d err=%v", r.Precopy, stopped, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrecopyDrainReceives100MillisecondBound(t *testing.T) {
|
||||
_, _, l, _ := precopyLayer(t, 1024, 1)
|
||||
calls := 0
|
||||
_, err := l.PrecopyDetachWithAdmission(context.Background(), func(ctx context.Context) (func(), error) {
|
||||
calls++
|
||||
deadline, ok := ctx.Deadline()
|
||||
if !ok || time.Until(deadline) > 100*time.Millisecond {
|
||||
t.Fatalf("unbounded pre-copy drain: deadline=%v present=%t", deadline, ok)
|
||||
}
|
||||
return nil, errors.New("controlled drain refusal")
|
||||
}, func() bool { t.Error("refused drain committed freeze"); return true })
|
||||
if calls == 0 || !errors.Is(err, ErrPrecopyNotConverged) {
|
||||
t.Fatalf("calls=%d err=%v", calls, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user