add some comments for the different WAL repair tests (#630)

The WAL repair tests look similar so added some extra comments to
clarify their purpose.

Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
This commit is contained in:
Krasi Georgiev 2019-06-12 16:10:37 +02:00 committed by GitHub
parent 6ab483071a
commit 3549c097b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -1045,7 +1045,9 @@ func TestHead_LogRollback(t *testing.T) {
testutil.Equals(t, []RefSeries{{Ref: 1, Labels: labels.FromStrings("a", "b")}}, series) 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 var enc RecordEncoder
for name, test := range map[string]struct { for name, test := range map[string]struct {
corrFunc func(rec []byte) []byte // Func that applies the corruption to a record. corrFunc func(rec []byte) []byte // Func that applies the corruption to a record.

View file

@ -27,7 +27,9 @@ import (
"github.com/prometheus/tsdb/testutil" "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 { for name, test := range map[string]struct {
corrSgm int // Which segment to corrupt. corrSgm int // Which segment to corrupt.
corrFunc func(f *os.File) // Func that applies the corruption. corrFunc func(f *os.File) // Func that applies the corruption.
@ -129,6 +131,10 @@ func TestWAL_Repair(t *testing.T) {
records = append(records, b) records = append(records, b)
testutil.Ok(t, w.Log(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()) testutil.Ok(t, w.Close())
f, err := os.OpenFile(SegmentName(dir, test.corrSgm), os.O_RDWR, 0666) 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) testutil.Ok(t, err)
defer w.Close() defer w.Close()
first, last, err := w.Segments() first, last, err = w.Segments()
testutil.Ok(t, err) testutil.Ok(t, err)
// Backfill segments from the most recent checkpoint onwards. // Backfill segments from the most recent checkpoint onwards.