Skip to content

Commit

Permalink
wal: improve reader_test log
Browse files Browse the repository at this point in the history
  • Loading branch information
caicancai authored and RaduBerinde committed Sep 23, 2024
1 parent 29f8fea commit 65c3ae1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion wal/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,16 @@ func TestReader(t *testing.T) {
if fields.HasValue("sync") {
require.NoError(t, f.Sync())
}

fmt.Fprintf(&buf, "%d..%d: write-garbage\n", offset, offset+int64(size))
case "corrupt-tail":
length := int64(fields.MustKeyValue("len").Int())
garbage := make([]byte, length)
rng.Read(garbage)
_, err := f.WriteAt(garbage, offset-length)
require.NoError(t, err)

fmt.Fprintf(&buf, "%d..%d: corrupt-tail\n", offset-length, offset)
default:
panic(fmt.Sprintf("unrecognized command %q", fields[0]))
}
Expand All @@ -206,7 +210,7 @@ func TestReader(t *testing.T) {
require.NoError(t, err)
log, ok := logs.Get(NumWAL(logNum))
if !ok {
return "not found"
return fmt.Sprintf("log with logNum %d not found", logNum)
}

segments := log.segments
Expand Down
4 changes: 3 additions & 1 deletion wal/testdata/reader
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ r.NextRecord() = (rr, (000003-002.log: 2373), 2652 from previous files, EOF)

read logNum=000004
----
not found
log with logNum 4 not found

# Test a corrupted log file that encodes a record too small to be a valid batch.
# The second "batch" only has a length of 5.
Expand Down Expand Up @@ -228,6 +228,7 @@ created "000005-001.log"
0..55: batch #95499
55..482: batch #95501
482..692: batch #95506
692..1045: write-garbage

read logNum=000005
----
Expand Down Expand Up @@ -345,6 +346,7 @@ created "000007.log"
55..482: batch #95501
482..692: batch #95506
692..46705: batch #95535
45685..46705: corrupt-tail

define logNum=000007 logNameIndex=001
batch count=19 seq=95535 size=45991 sync
Expand Down

0 comments on commit 65c3ae1

Please sign in to comment.