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 "database/sql/driver"
5 "errors"
6 "testing"
7)
8
9func TestPlan9Fix1CleanupErrorPreservedAlongsideCallbackFailure(t *testing.T) {
10 s := openGatedStore(t)
11 seedGateApp(t, s)
12 callbackErr := errors.New("callback failed with an open transaction")
13 err := s.withClaimSQL(t.Context(), []claimSQLScope{gateScope}, allowAllClaimSQL, func(v *Store) error {
14 tx, err := v.db.BeginTx(t.Context(), nil)
15 if err != nil {
16 return err
17 }
18 if _, err := tx.Exec(`UPDATE audit SET action='uncommitted' WHERE account_id=7 AND app='blog'`); err != nil {
19 return err
20 }
21 return callbackErr
22 })
23 if !errors.Is(err, callbackErr) || !errors.Is(err, ErrClaimSQLScope) {
24 t.Fatalf("callback or forced-cleanup failure lost: %v", err)
25 }
26}
27
28func TestPlan9Fix1UnbindReportsWrittenTransactionStillAwaitingRollback(t *testing.T) {
29 s := openGatedStore(t)
30 seedGateApp(t, s)
31 err := s.withClaimSQL(t.Context(), []claimSQLScope{gateScope}, allowAllClaimSQL, func(v *Store) error {
32 return v.db.(*claimBoundDB).conn.Raw(func(dc any) error {
33 c := dc.(*claimConn)
34 // Model awaitDone having marked the public transaction done while its
35 // driver rollback is still queued. closeHandles cannot join that handle.
36 if _, err := c.BeginTx(t.Context(), driver.TxOptions{}); err != nil {
37 return err
38 }
39 _, err := c.ExecContext(t.Context(), `UPDATE audit SET action='rollback-pending' WHERE account_id=7 AND app='blog'`, nil)
40 return err
41 })
42 })
43 if !errors.Is(err, ErrClaimSQLScope) {
44 t.Fatalf("scope lost writes while reporting success: %v", err)
45 }
46 if countWhere(t, s, "audit", "action='rollback-pending'") != 0 {
47 t.Fatal("abandoned transaction committed")
48 }
49}
50