carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import (
4 "context"
5 "fmt"
6 "testing"
7)
8
9// These acceptance tests stay red until Paul selects the transaction contract.
10func TestPlan9SQLAuthorityChecksDoNotHoldConnection(t *testing.T) {
11 s := openGatedStore(t)
12 seedGateApp(t, s)
13 check := func(context.Context, claimSQLScope) error {
14 if n := s.rawPool.Stats().InUse; n != 0 {
15 return fmt.Errorf("authority read holds %d SQLite connections", n)
16 }
17 return nil
18 }
19 err := s.withClaimSQL(gateCtx(t), []claimSQLScope{gateScope}, check, func(v *Store) error {
20 _, err := v.db.Exec(`UPDATE audit SET action='checked' WHERE account_id=7 AND app='blog'`)
21 return err
22 })
23 if err != nil {
24 t.Fatal(err)
25 }
26}
27
28func TestPlan9SQLChecksOncePerTransaction(t *testing.T) {
29 s := openGatedStore(t)
30 seedGateApp(t, s)
31 checks := 0
32 err := s.withClaimSQL(gateCtx(t), []claimSQLScope{gateScope}, func(context.Context, claimSQLScope) error {
33 checks++
34 return nil
35 }, func(v *Store) error {
36 tx, err := v.db.Begin()
37 if err != nil {
38 return err
39 }
40 defer tx.Rollback()
41 for _, action := range []string{"first", "second"} {
42 if _, err := tx.Exec(`UPDATE audit SET action=? WHERE account_id=7 AND app='blog'`, action); err != nil {
43 return err
44 }
45 }
46 return tx.Commit()
47 })
48 if err != nil {
49 t.Fatal(err)
50 }
51 if checks != 1 {
52 t.Fatalf("remote checks=%d, want one preparation before acquiring connection", checks)
53 }
54}
55