Fix crc64 unit test

This commit is contained in:
Ben Johnson
2021-01-16 10:04:03 -07:00
parent 6ac6a8536d
commit 07a65cbac7
2 changed files with 8 additions and 2 deletions

6
db.go
View File

@@ -1485,6 +1485,12 @@ func (db *DB) CRC64() (uint64, Pos, error) {
db.mu.Lock() db.mu.Lock()
defer db.mu.Unlock() defer db.mu.Unlock()
if err := db.init(); err != nil {
return 0, Pos{}, err
} else if db.db == nil {
return 0, Pos{}, os.ErrNotExist
}
// Force a RESTART checkpoint to ensure the database is at the start of the WAL. // Force a RESTART checkpoint to ensure the database is at the start of the WAL.
if err := db.checkpoint(CheckpointModeRestart); err != nil { if err := db.checkpoint(CheckpointModeRestart); err != nil {
return 0, Pos{}, err return 0, Pos{}, err

View File

@@ -137,8 +137,8 @@ func TestDB_CRC64(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} else if chksum1, _, err := db.CRC64(); err != nil { } else if chksum1, _, err := db.CRC64(); err != nil {
t.Fatal(err) t.Fatal(err)
} else if chksum0 != chksum1 { } else if chksum0 == chksum1 {
t.Fatal("expected equal checksum after WAL change") t.Fatal("expected different checksum event after WAL change")
} }
// Checkpoint change into database. Checksum should change. // Checkpoint change into database. Checksum should change.