(t *testing.T)
| 129 | } |
| 130 | |
| 131 | func TestStore_Integration(t *testing.T) { |
| 132 | if testing.Short() { |
| 133 | t.Skip("skipping integration test in short mode") |
| 134 | } |
| 135 | |
| 136 | const factor = 1 |
| 137 | |
| 138 | db := testingutil.NewDB(t, filepath.Join(t.TempDir(), "db")) |
| 139 | db.MonitorInterval = factor * 100 * time.Millisecond |
| 140 | db.Replica = litestream.NewReplica(db) |
| 141 | db.Replica.Client = file.NewReplicaClient(t.TempDir()) |
| 142 | if err := db.Open(); err != nil { |
| 143 | t.Fatal(err) |
| 144 | } |
| 145 | sqldb := testingutil.MustOpenSQLDB(t, db.Path()) |
| 146 | defer testingutil.MustCloseSQLDB(t, sqldb) |
| 147 | |
| 148 | store := litestream.NewStore([]*litestream.DB{db}, litestream.CompactionLevels{ |
| 149 | {Level: 0}, |
| 150 | {Level: 1, Interval: factor * 200 * time.Millisecond}, |
| 151 | {Level: 2, Interval: factor * 500 * time.Millisecond}, |
| 152 | }) |
| 153 | store.SnapshotInterval = factor * 1 * time.Second |
| 154 | if err := store.Open(t.Context()); err != nil { |
| 155 | t.Fatal(err) |
| 156 | } |
| 157 | defer store.Close(t.Context()) |
| 158 | |
| 159 | // Create initial table |
| 160 | if _, err := sqldb.ExecContext(t.Context(), `CREATE TABLE t (id INTEGER PRIMARY KEY, val TEXT);`); err != nil { |
| 161 | t.Fatal(err) |
| 162 | } |
| 163 | |
| 164 | // Run test for a fixed duration. |
| 165 | done := make(chan struct{}) |
| 166 | time.AfterFunc(10*time.Second, func() { close(done) }) |
| 167 | |
| 168 | // Channel for insert errors |
| 169 | insertErr := make(chan error, 1) |
| 170 | |
| 171 | // WaitGroup to ensure insert goroutine completes before cleanup |
| 172 | var wg sync.WaitGroup |
| 173 | |
| 174 | // Wait for insert goroutine to finish before cleanup & surface any errors. |
| 175 | defer func() { |
| 176 | wg.Wait() |
| 177 | |
| 178 | select { |
| 179 | case err := <-insertErr: |
| 180 | t.Fatalf("insert error during test: %v", err) |
| 181 | default: |
| 182 | // No insert errors |
| 183 | } |
| 184 | }() |
| 185 | |
| 186 | // Start goroutine to continuously insert records |
| 187 | wg.Add(1) |
| 188 | go func() { |
nothing calls this directly
no test coverage detected