carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package lease
2
3import (
4 "context"
5 "path/filepath"
6 "testing"
7 "time"
8
9 lss3 "github.com/benbjohnson/litestream/s3"
10)
11
12// A hibernating instance's replica keeps the same recovery window the
13// box-wide replicator does (#263). litestream's own default is 24h, which
14// a wake would enforce, deleting every snapshot older than a day.
15func TestNewStorePinsTheRecoveryWindow(t *testing.T) {
16 l := lss3.NewLeaser()
17 l.Path = "instances/x.example/inc"
18 h := &Held{leaser: l, replicaClient: &generationFake{}}
19 store, db, err := h.newStore(filepath.Join(t.TempDir(), "db"), time.Second)
20 if err != nil {
21 t.Fatal(err)
22 }
23 if store.SnapshotRetention != SnapshotRetention || SnapshotRetention != 7*24*time.Hour {
24 t.Errorf("SnapshotRetention = %v (constant %v), want 7 days", store.SnapshotRetention, SnapshotRetention)
25 }
26 if store.SnapshotInterval != SnapshotInterval || SnapshotInterval != 24*time.Hour {
27 t.Errorf("SnapshotInterval = %v (constant %v), want 24h", store.SnapshotInterval, SnapshotInterval)
28 }
29 if !store.RetentionEnabled || !db.RetentionEnabled {
30 t.Error("retention disabled on an unbound store; the window must be enforced, not only stated")
31 }
32}
33
34// A bound generation (an instance move) keeps retention off whatever the
35// window says: the new setting must not turn it back on.
36func TestNewStoreWindowLeavesAGenerationsRetentionOff(t *testing.T) {
37 l := lss3.NewLeaser()
38 l.Path = "instances/x.example/inc"
39 h := &Held{leaser: l, replicaClient: &generationFake{}}
40 if err := h.BindGeneration(l.Path+"/g-one/", func(context.Context) error { return nil }); err != nil {
41 t.Fatal(err)
42 }
43 store, db, err := h.newStore(filepath.Join(t.TempDir(), "db"), time.Second)
44 if err != nil {
45 t.Fatal(err)
46 }
47 if store.RetentionEnabled || db.RetentionEnabled {
48 t.Fatal("a bound generation's store has retention on")
49 }
50}
51