oficina / home Public

Clone
git clone https://amadan.net/oficina/home

Plain git — no account needed to clone.

Download

Download this file

1package home
2
3import (
4 "path/filepath"
5 "testing"
6
7 "amadan.net/rastrillo/rastrillo/db"
8)
9
10// TestOpenDatabaseCommitsDurably: the database cmd/home opens syncs the
11// WAL on every commit, PRAGMA synchronous = 2 (FULL), on the writer that
12// commits and on the readers. db.Open's own default since rastrillo
13// v0.34.0 is NORMAL (1), which is the control: it must differ, or this
14// test proves nothing.
15func TestOpenDatabaseCommitsDurably(t *testing.T) {
16 RegisterSecureDelete()
17 d, err := OpenDatabase(filepath.Join(t.TempDir(), "home.db"), quietLogger())
18 if err != nil {
19 t.Fatal(err)
20 }
21 t.Cleanup(func() { d.Close() })
22 var w, r int
23 if err := d.Writer().QueryRow("PRAGMA synchronous").Scan(&w); err != nil {
24 t.Fatal(err)
25 }
26 if err := d.Reader().QueryRow("PRAGMA synchronous").Scan(&r); err != nil {
27 t.Fatal(err)
28 }
29 if w != 2 || r != 2 {
30 t.Fatalf("PRAGMA synchronous: writer %d, reader %d; want 2 (FULL) on both", w, r)
31 }
32
33 plain, err := db.Open(filepath.Join(t.TempDir(), "plain.db"), quietLogger())
34 if err != nil {
35 t.Fatal(err)
36 }
37 t.Cleanup(func() { plain.Close() })
38 var p int
39 if err := plain.Writer().QueryRow("PRAGMA synchronous").Scan(&p); err != nil {
40 t.Fatal(err)
41 }
42 if p == 2 {
43 t.Fatal("control: db.Open without DurableCommits is FULL too, so this test cannot tell the option is applied")
44 }
45}
46