mirror of
https://github.com/rqlite/rqlite.git
synced 2026-01-25 04:16:26 +00:00
Add another preupdate hook unit test
This commit is contained in:
@@ -413,6 +413,33 @@ func Test_Preupdate_Multi(t *testing.T) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
// Test_Preupdate_Tx demostrates that the preupdate hook is called for
|
||||
// transactions which is rolled back.
|
||||
func Test_Preupdate_Tx(t *testing.T) {
|
||||
path := mustTempPath()
|
||||
defer os.Remove(path)
|
||||
db, err := Open(path, false, false)
|
||||
if err != nil {
|
||||
t.Fatalf("error opening database")
|
||||
}
|
||||
defer db.Close()
|
||||
mustExecute(db, "CREATE TABLE foo (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
|
||||
var wg sync.WaitGroup
|
||||
hook := func(got *command.CDCEvent) error {
|
||||
defer wg.Done()
|
||||
return nil
|
||||
}
|
||||
if err := db.RegisterPreUpdateHook(hook, false); err != nil {
|
||||
t.Fatalf("error registering preupdate hook")
|
||||
}
|
||||
wg.Add(1)
|
||||
mustExecute(db, "BEGIN")
|
||||
mustExecute(db, "INSERT INTO foo(id, name) VALUES(1, 'fiona')")
|
||||
mustExecute(db, "ROLLBACK")
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func compareEvents(t *testing.T, exp, got *command.CDCEvent) {
|
||||
t.Helper()
|
||||
if exp, got := exp.Table, got.Table; exp != got {
|
||||
|
||||
Reference in New Issue
Block a user