package lease import ( "context" "path/filepath" "testing" "time" lss3 "github.com/benbjohnson/litestream/s3" ) // A hibernating instance's replica keeps the same recovery window the // box-wide replicator does (#263). litestream's own default is 24h, which // a wake would enforce, deleting every snapshot older than a day. func TestNewStorePinsTheRecoveryWindow(t *testing.T) { l := lss3.NewLeaser() l.Path = "instances/x.example/inc" h := &Held{leaser: l, replicaClient: &generationFake{}} store, db, err := h.newStore(filepath.Join(t.TempDir(), "db"), time.Second) if err != nil { t.Fatal(err) } if store.SnapshotRetention != SnapshotRetention || SnapshotRetention != 7*24*time.Hour { t.Errorf("SnapshotRetention = %v (constant %v), want 7 days", store.SnapshotRetention, SnapshotRetention) } if store.SnapshotInterval != SnapshotInterval || SnapshotInterval != 24*time.Hour { t.Errorf("SnapshotInterval = %v (constant %v), want 24h", store.SnapshotInterval, SnapshotInterval) } if !store.RetentionEnabled || !db.RetentionEnabled { t.Error("retention disabled on an unbound store; the window must be enforced, not only stated") } } // A bound generation (an instance move) keeps retention off whatever the // window says: the new setting must not turn it back on. func TestNewStoreWindowLeavesAGenerationsRetentionOff(t *testing.T) { l := lss3.NewLeaser() l.Path = "instances/x.example/inc" h := &Held{leaser: l, replicaClient: &generationFake{}} if err := h.BindGeneration(l.Path+"/g-one/", func(context.Context) error { return nil }); err != nil { t.Fatal(err) } store, db, err := h.newStore(filepath.Join(t.TempDir(), "db"), time.Second) if err != nil { t.Fatal(err) } if store.RetentionEnabled || db.RetentionEnabled { t.Fatal("a bound generation's store has retention on") } }