From 379cb4575e84c27c63af566a449d66913ef92fcd Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 30 Jan 2024 09:28:28 -0500 Subject: [PATCH] Comments --- db/db_checkpoint_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/db/db_checkpoint_test.go b/db/db_checkpoint_test.go index d6ead94d..be9c4684 100644 --- a/db/db_checkpoint_test.go +++ b/db/db_checkpoint_test.go @@ -158,7 +158,7 @@ func Test_WALDatabaseCheckpoint_RestartTimeout(t *testing.T) { } // 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 + // to confirm that after a non-completing RESTART checkpoint, a write does // not RESET the WAL file. walSzPre := mustFileSize(db.WALPath()) hdrPre := mustGetWALHeader(db.WALPath()) @@ -233,6 +233,25 @@ func Test_WALDatabaseCheckpoint_TruncateTimeout(t *testing.T) { t.Fatalf("wal file should be unchanged after checkpoint failure") } + // Confirm that the next write to the WAL is appended to the WAL file, and doesn't + // overwrite the first page i.e. that the WAL is not reset. + 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()) + } + rows, err = db.QueryStringStmt(`SELECT COUNT(*) FROM foo`) + if err != nil { + t.Fatalf("failed to execute query on single node: %s", err.Error()) + } + if exp, got := `[{"columns":["COUNT(*)"],"types":["integer"],"values":[[51]]}]`, asJSON(rows); exp != got { + t.Fatalf("expected %s, got %s", exp, got) + } + hdrPost := mustGetWALHeader(db.WALPath()) + if !bytes.Equal(hdrPre, hdrPost) { + t.Fatalf("wal file header should be unchanged after post-failed-TRUNCATE checkpoint write") + } + blockingDB.Close() if err := db.CheckpointWithTimeout(CheckpointTruncate, 250*time.Millisecond); err != nil { t.Fatalf("failed to checkpoint database: %s", err.Error())