1
0
Fork 0

Increase CHECKPOINT test coverage

master
Philip O'Toole 8 months ago
parent cf594a29b7
commit 1c83e5b83b

@ -2,9 +2,12 @@ package db
import (
"bytes"
"io"
"os"
"testing"
"time"
"github.com/rqlite/rqlite/v8/db/wal"
)
// Test_WALDatabaseCheckpointOKNoWAL tests that a checkpoint succeeds
@ -154,6 +157,27 @@ func Test_WALDatabaseCheckpoint_RestartTimeout(t *testing.T) {
t.Fatal("expected error due to failure to checkpoint")
}
// Get some information on the WAL file before the checkpoint. The goal here is
// to confirm that after a non-completing TRUNCATE checkpoint, a write does
// not RESET the WAL file.
walSzPre := mustFileSize(db.WALPath())
hdrPre := mustGetWALHeader(db.WALPath())
_, err = db.ExecuteStringStmt(`INSERT INTO foo(name) VALUES("fiona")`)
if err != nil {
t.Fatalf("failed to execute INSERT on single node: %s", err.Error())
}
// Check that the WAL file has grown, because we want to ensure that the next write
// is appended to the WAL file, and doesn't overwrite the first page.
walSzPost := mustFileSize(db.WALPath())
hdrPost := mustGetWALHeader(db.WALPath())
if walSzPost <= walSzPre {
t.Fatalf("wal file should have grown after post-failed-checkpoint write")
}
if !bytes.Equal(hdrPre, hdrPost) {
t.Fatalf("wal file header should be unchanged after post-failed-checkpoint write")
}
blockingDB.Close()
if err := db.CheckpointWithTimeout(CheckpointRestart, 250*time.Millisecond); err != nil {
t.Fatalf("failed to checkpoint database: %s", err.Error())
@ -225,3 +249,17 @@ func mustReadBytes(path string) []byte {
}
return b
}
func mustGetWALHeader(path string) []byte {
fd, err := os.Open(path)
if err != nil {
panic(err)
}
defer fd.Close()
hdr := make([]byte, wal.WALHeaderSize)
_, err = io.ReadFull(fd, hdr)
if err != nil {
panic(err)
}
return hdr
}

Loading…
Cancel
Save