MCPcopy
hub / github.com/rqlite/rqlite / Test_CommitHook

Function Test_CommitHook

db/db_commit_hook_test.go:9–34  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func Test_CommitHook(t *testing.T) {
10 path := mustTempPath()
11 defer os.Remove(path)
12 db, err := Open(path, false, false)
13 if err != nil {
14 t.Fatalf("error opening database")
15 }
16 defer db.Close()
17 mustExecute(db, "CREATE TABLE foo (id INTEGER PRIMARY KEY, name TEXT)")
18
19 count := &atomic.Int32{}
20 hook := func() bool {
21 count.Add(1)
22 return true
23 }
24 if err := db.RegisterCommitHook(hook); err != nil {
25 t.Fatalf("error registering commit hook")
26 }
27
28 // A select should not trigger the hook and a basic insert should trigger the hook.
29 mustQuery(db, "SELECT * FROM foo")
30 mustExecute(db, "INSERT INTO foo(name) VALUES('fiona')")
31 if count.Load() != 1 {
32 t.Fatalf("expected count 1, got %d", count.Load())
33 }
34}
35
36// Test_CommitHook_Rollback demonstrates that the Commit hook is not called for a
37// transaction which is rolled back.

Callers

nothing calls this directly

Calls 9

mustTempPathFunction · 0.85
OpenFunction · 0.85
mustExecuteFunction · 0.70
mustQueryFunction · 0.70
RemoveMethod · 0.65
CloseMethod · 0.65
LoadMethod · 0.65
AddMethod · 0.45
RegisterCommitHookMethod · 0.45

Tested by

no test coverage detected