diff --git a/head_test.go b/head_test.go index dbe6fecd5a..7f3579b549 100644 --- a/head_test.go +++ b/head_test.go @@ -1045,7 +1045,9 @@ func TestHead_LogRollback(t *testing.T) { testutil.Equals(t, []RefSeries{{Ref: 1, Labels: labels.FromStrings("a", "b")}}, series) } -func TestWalRepair(t *testing.T) { +// TestWalRepair_DecodingError ensures that a repair is run for an error +// when decoding a record. +func TestWalRepair_DecodingError(t *testing.T) { var enc RecordEncoder for name, test := range map[string]struct { corrFunc func(rec []byte) []byte // Func that applies the corruption to a record. diff --git a/wal/wal_test.go b/wal/wal_test.go index 577ae5fd0e..50761e07a8 100644 --- a/wal/wal_test.go +++ b/wal/wal_test.go @@ -27,7 +27,9 @@ import ( "github.com/prometheus/tsdb/testutil" ) -func TestWAL_Repair(t *testing.T) { +// TestWALRepair_ReadingError ensures that a repair is run for an error +// when reading a record. +func TestWALRepair_ReadingError(t *testing.T) { for name, test := range map[string]struct { corrSgm int // Which segment to corrupt. corrFunc func(f *os.File) // Func that applies the corruption. @@ -129,6 +131,10 @@ func TestWAL_Repair(t *testing.T) { records = append(records, b) testutil.Ok(t, w.Log(b)) } + first, last, err := w.Segments() + testutil.Ok(t, err) + testutil.Equals(t, 3, 1+last-first, "wal creation didn't result in expected number of segments") + testutil.Ok(t, w.Close()) f, err := os.OpenFile(SegmentName(dir, test.corrSgm), os.O_RDWR, 0666) @@ -143,7 +149,7 @@ func TestWAL_Repair(t *testing.T) { testutil.Ok(t, err) defer w.Close() - first, last, err := w.Segments() + first, last, err = w.Segments() testutil.Ok(t, err) // Backfill segments from the most recent checkpoint onwards.