package console import ( "context" "fmt" "testing" ) // These acceptance tests stay red until Paul selects the transaction contract. func TestPlan9SQLAuthorityChecksDoNotHoldConnection(t *testing.T) { s := openGatedStore(t) seedGateApp(t, s) check := func(context.Context, claimSQLScope) error { if n := s.rawPool.Stats().InUse; n != 0 { return fmt.Errorf("authority read holds %d SQLite connections", n) } return nil } err := s.withClaimSQL(gateCtx(t), []claimSQLScope{gateScope}, check, func(v *Store) error { _, err := v.db.Exec(`UPDATE audit SET action='checked' WHERE account_id=7 AND app='blog'`) return err }) if err != nil { t.Fatal(err) } } func TestPlan9SQLChecksOncePerTransaction(t *testing.T) { s := openGatedStore(t) seedGateApp(t, s) checks := 0 err := s.withClaimSQL(gateCtx(t), []claimSQLScope{gateScope}, func(context.Context, claimSQLScope) error { checks++ return nil }, func(v *Store) error { tx, err := v.db.Begin() if err != nil { return err } defer tx.Rollback() for _, action := range []string{"first", "second"} { if _, err := tx.Exec(`UPDATE audit SET action=? WHERE account_id=7 AND app='blog'`, action); err != nil { return err } } return tx.Commit() }) if err != nil { t.Fatal(err) } if checks != 1 { t.Fatalf("remote checks=%d, want one preparation before acquiring connection", checks) } }