mirror of
https://github.com/benbjohnson/litestream.git
synced 2026-01-25 05:06:30 +00:00
fix(test): resolve flaky TestStore_CompactDB/L1 timing issue (#920)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/benbjohnson/litestream"
|
"github.com/benbjohnson/litestream"
|
||||||
"github.com/benbjohnson/litestream/file"
|
"github.com/benbjohnson/litestream/file"
|
||||||
"github.com/benbjohnson/litestream/internal/testingutil"
|
"github.com/benbjohnson/litestream/internal/testingutil"
|
||||||
@@ -44,20 +46,23 @@ func TestStore_CompactDB(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := s.CompactDB(t.Context(), db0, levels[1]); err != nil {
|
_, err := s.CompactDB(t.Context(), db0, levels[1])
|
||||||
t.Fatal(err)
|
require.NoError(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Re-compacting immediately should return an error that it's too soon.
|
// Re-compacting immediately should return an error indicating compaction
|
||||||
if _, err := s.CompactDB(t.Context(), db0, levels[1]); !errors.Is(err, litestream.ErrCompactionTooEarly) {
|
// cannot proceed. This may be ErrCompactionTooEarly (detected timing conflict)
|
||||||
t.Fatalf("unexpected error: %s", err)
|
// or ErrNoCompaction (no new files to compact). Both are valid outcomes
|
||||||
}
|
// depending on whether we crossed a second boundary during the first compaction
|
||||||
|
// (PrevCompactionAt truncates to seconds, causing edge cases at boundaries).
|
||||||
|
_, err = s.CompactDB(t.Context(), db0, levels[1])
|
||||||
|
require.True(t,
|
||||||
|
errors.Is(err, litestream.ErrCompactionTooEarly) || errors.Is(err, litestream.ErrNoCompaction),
|
||||||
|
"expected ErrCompactionTooEarly or ErrNoCompaction, got: %v", err)
|
||||||
|
|
||||||
// Re-compacting after the interval should show that there is nothing to compact.
|
// Re-compacting after the interval should show that there is nothing to compact.
|
||||||
time.Sleep(levels[1].Interval)
|
time.Sleep(levels[1].Interval)
|
||||||
if _, err := s.CompactDB(t.Context(), db0, levels[1]); !errors.Is(err, litestream.ErrNoCompaction) {
|
_, err = s.CompactDB(t.Context(), db0, levels[1])
|
||||||
t.Fatalf("unexpected error: %s", err)
|
require.ErrorIs(t, err, litestream.ErrNoCompaction)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Snapshot", func(t *testing.T) {
|
t.Run("Snapshot", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user