mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test: cover expired delete sweeps and the last-progress window
This commit is contained in:
1 parent
cb1c929350
commit
37efdef9da
1 file changed
+73
@@ -84,3 +84,76 @@ func TestVolumeDeleteContinuesAcrossTransientObjectFailures(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A real expired child context must not expire the next sweep. Unlike the
|
||||
// immediate error controls, this filer blocks an exchange until its deadline.
|
||||
type waitingDeleteFiler struct {
|
||||
*memChunkStore
|
||||
bound time.Duration
|
||||
calls int
|
||||
waited bool
|
||||
stall bool
|
||||
removedAt time.Time
|
||||
}
|
||||
|
||||
func (f *waitingDeleteFiler) DeleteEntry(ctx context.Context, dir, name string, expected map[string][]byte) error {
|
||||
f.calls++
|
||||
if f.calls == 1 {
|
||||
timer := time.NewTimer(f.bound / 2)
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case <-timer.C:
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
err := f.memChunkStore.DeleteEntry(ctx, dir, name, expected)
|
||||
if err == nil {
|
||||
f.removedAt = time.Now()
|
||||
}
|
||||
return err
|
||||
}
|
||||
if f.stall {
|
||||
return status.Error(codes.Unavailable, "stalled after first removal")
|
||||
}
|
||||
if !f.waited {
|
||||
f.waited = true
|
||||
<-ctx.Done()
|
||||
return ctx.Err()
|
||||
}
|
||||
return f.memChunkStore.DeleteEntry(ctx, dir, name, expected)
|
||||
}
|
||||
|
||||
func TestVolumeDeleteRefreshesAnExpiredSweepAndWaitsFromLastRemoval(t *testing.T) {
|
||||
for _, stall := range []bool{false, true} {
|
||||
name := "expired-sweep"
|
||||
if stall {
|
||||
name = "progress-then-stall"
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
store := newMemChunkStore()
|
||||
useMemChunkStore(t, store)
|
||||
v := cliVolume(t, store, name, "daily")
|
||||
bound := 600 * time.Millisecond
|
||||
f := &waitingDeleteFiler{memChunkStore: store, bound: bound, stall: stall}
|
||||
dialChunkFiler = func(string) (chunkstore.Filer, func() error, error) { return f, func() error { return nil }, nil }
|
||||
addr := startFakeLifecycle(t, &fakeLifecycle{})
|
||||
code, out, logs := runChunk(cliArgs("volume-delete", volArgs("volume", v), []string{"--master", addr, "--request-id", "timed-delete", "--timeout", bound.String()})...)
|
||||
if f.removedAt.IsZero() {
|
||||
t.Fatalf("fixture made no progress: %d %s", code, out)
|
||||
}
|
||||
if !stall {
|
||||
if code != 0 || !f.waited || !strings.Contains(logs, "deleted 2 of 2") {
|
||||
t.Fatalf("fresh sweep: %d %s %s", code, out, logs)
|
||||
}
|
||||
return
|
||||
}
|
||||
e := chunkErrorOut(t, out)
|
||||
if code != 1 || e.Code != "unavailable" || !e.Retryable || !strings.Contains(e.Message, "deleted 1 of 2") || !strings.Contains(e.Message, "stalled after first removal") {
|
||||
t.Fatalf("stall after progress: %d %s", code, out)
|
||||
}
|
||||
if elapsed := time.Since(f.removedAt); elapsed < bound || elapsed > bound+2*time.Second {
|
||||
t.Fatalf("no-progress window from last removal = %s, want [%s,%s]", elapsed, bound, bound+2*time.Second)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user