MCPcopy
hub / github.com/benbjohnson/litestream / TestVFSFile_PendingIndexIsolation

Function TestVFSFile_PendingIndexIsolation

vfs_test.go:66–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestVFSFile_PendingIndexIsolation(t *testing.T) {
67 client := newMockReplicaClient()
68 client.addFixture(t, buildLTXFixture(t, 1, 'a'))
69
70 f := NewVFSFile(client, "test.db", slog.Default())
71 if err := f.Open(); err != nil {
72 t.Fatalf("open vfs file: %v", err)
73 }
74
75 if err := f.Lock(sqlite3vfs.LockShared); err != nil {
76 t.Fatalf("lock shared: %v", err)
77 }
78
79 client.addFixture(t, buildLTXFixture(t, 2, 'b'))
80 if err := f.pollReplicaClient(context.Background()); err != nil {
81 t.Fatalf("poll replica: %v", err)
82 }
83
84 f.mu.Lock()
85 pendingLen := len(f.pending)
86 current := f.index[1]
87 f.mu.Unlock()
88
89 if pendingLen == 0 {
90 t.Fatalf("expected pending index entries while shared lock held")
91 }
92 if current.MinTXID != 1 {
93 t.Fatalf("main index should still reference first txid, got %s", current.MinTXID)
94 }
95
96 buf := make([]byte, 4096)
97 if _, err := f.ReadAt(buf, 0); err != nil {
98 t.Fatalf("read during lock: %v", err)
99 }
100 if buf[0] != 'a' {
101 t.Fatalf("expected old data during lock, got %q", buf[0])
102 }
103
104 if err := f.Unlock(sqlite3vfs.LockNone); err != nil {
105 t.Fatalf("unlock: %v", err)
106 }
107
108 if _, err := f.ReadAt(buf, 0); err != nil {
109 t.Fatalf("read after unlock: %v", err)
110 }
111 if buf[0] != 'b' {
112 t.Fatalf("expected updated data after unlock, got %q", buf[0])
113 }
114}
115
116func TestVFSFile_PendingIndexRace(t *testing.T) {
117 client := newMockReplicaClient()

Callers

nothing calls this directly

Calls 9

OpenMethod · 0.95
LockMethod · 0.95
pollReplicaClientMethod · 0.95
UnlockMethod · 0.95
ReadAtMethod · 0.95
newMockReplicaClientFunction · 0.85
buildLTXFixtureFunction · 0.85
NewVFSFileFunction · 0.85
addFixtureMethod · 0.80

Tested by

no test coverage detected