Repository navigation
Expand file tree
/
Copy pathwal_open_test.go
More file actions
75 lines (71 loc) · 2.22 KB
/
Copy pathwal_open_test.go
File metadata and controls
75 lines (71 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2026 The liustack/sqlite Authors.
// SPDX-License-Identifier: MIT
// Use of this source code is governed by the MIT license in LICENSE at the
// root of this repository.
package sqlite
import (
"strings"
"sync"
"testing"
)
// Processes that open a new file at the same time all open it: each asks
// for WAL as its connection opens, the driver by itself or the DSN, and
// SQLite gives the ones that ask while another changes the mode SQLITE_BUSY
// without waiting.
func TestJournalModeWALOpenedAtOnceByProcesses(t *testing.T) {
rounds := 8
if testing.Short() {
rounds = 2
}
for _, query := range []string{"", "?_pragma=journal_mode(WAL)"} {
for round := range rounds {
path := mPath(t)
peers := make([]*peer, 6)
for i := range peers {
peers[i] = startPeerDSN(t, "driver", path, "file:"+path+query)
}
start := make(chan struct{})
out := make([]string, len(peers))
var wg sync.WaitGroup
for i, p := range peers {
wg.Go(func() {
<-start
// The first statement opens the connection.
out[i] = p.do("CREATE TABLE IF NOT EXISTS t (x)")
})
}
close(start)
wg.Wait()
for _, o := range out {
if strings.Contains(o, "error") {
t.Fatalf("DSN %q, round %d: a process got %q", query, round, o)
}
}
if got := peers[0].do("PRAGMA journal_mode"); got != "wal" {
t.Fatalf("DSN %q, round %d: journal_mode is %s, want wal", query, round, got)
}
for _, p := range peers {
p.stop()
}
}
}
}
// Which _pragma values the driver runs as its own request for WAL.
func TestPragmaSetsWAL(t *testing.T) {
for p, want := range map[string]bool{
"journal_mode(WAL)": true,
"journal_mode=wal": true,
"main.JOURNAL_MODE = 'wal'": true,
" journal_mode ( \"WAL\" ) ; ": true,
"journal_mode": false,
"journal_mode(delete)": false,
"aux.journal_mode(wal)": false,
"journal_mode=wal; PRAGMA synchronous=1": false,
"synchronous(wal)": false,
"journal_mode(wal": false,
} {
if got := pragmaSetsWAL(p); got != want {
t.Errorf("pragmaSetsWAL(%q) is %v, want %v", p, got, want)
}
}
}