(f *testing.F)
| 15 | ) |
| 16 | |
| 17 | func FuzzRestoreWithMissingCompactedFile(f *testing.F) { |
| 18 | f.Add(int64(1)) |
| 19 | f.Add(int64(2)) |
| 20 | f.Add(int64(3)) |
| 21 | |
| 22 | f.Fuzz(func(t *testing.T, seed int64) { |
| 23 | if testing.Short() { |
| 24 | t.Skip("skipping fuzz test in short mode") |
| 25 | } |
| 26 | |
| 27 | rng := rand.New(rand.NewSource(seed)) |
| 28 | ctx := t.Context() |
| 29 | |
| 30 | db := testingutil.NewDB(t, filepath.Join(t.TempDir(), "db")) |
| 31 | db.MonitorInterval = 20 * time.Millisecond |
| 32 | db.Replica = litestream.NewReplica(db) |
| 33 | db.Replica.SyncInterval = 20 * time.Millisecond |
| 34 | client := file.NewReplicaClient(t.TempDir()) |
| 35 | db.Replica.Client = client |
| 36 | |
| 37 | if err := db.Open(); err != nil { |
| 38 | t.Fatal(err) |
| 39 | } |
| 40 | sqldb := testingutil.MustOpenSQLDB(t, db.Path()) |
| 41 | defer testingutil.MustCloseDBs(t, db, sqldb) |
| 42 | |
| 43 | store := litestream.NewStore([]*litestream.DB{db}, litestream.CompactionLevels{ |
| 44 | {Level: 0}, |
| 45 | {Level: 1, Interval: 50 * time.Millisecond}, |
| 46 | {Level: 2, Interval: 150 * time.Millisecond}, |
| 47 | }) |
| 48 | store.SnapshotInterval = 200 * time.Millisecond |
| 49 | if err := store.Open(ctx); err != nil { |
| 50 | t.Fatal(err) |
| 51 | } |
| 52 | defer store.Close(ctx) |
| 53 | |
| 54 | if _, err := sqldb.ExecContext(ctx, `CREATE TABLE t (id INTEGER PRIMARY KEY, val TEXT);`); err != nil { |
| 55 | t.Fatal(err) |
| 56 | } |
| 57 | |
| 58 | done := make(chan struct{}) |
| 59 | var wg sync.WaitGroup |
| 60 | wg.Add(1) |
| 61 | go func() { |
| 62 | defer wg.Done() |
| 63 | ticker := time.NewTicker(5 * time.Millisecond) |
| 64 | defer ticker.Stop() |
| 65 | |
| 66 | for { |
| 67 | select { |
| 68 | case <-ctx.Done(): |
| 69 | return |
| 70 | case <-done: |
| 71 | return |
| 72 | case <-ticker.C: |
| 73 | if _, err := sqldb.ExecContext(ctx, `INSERT INTO t (val) VALUES (?);`, time.Now().String()); err != nil { |
| 74 | return |
nothing calls this directly
no test coverage detected