MCPcopy
hub / github.com/go-gorm/gorm / TestCancelTransaction

Function TestCancelTransaction

tests/transaction_test.go:76–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestCancelTransaction(t *testing.T) {
77 ctx := context.Background()
78 ctx, cancelFunc := context.WithCancel(ctx)
79 cancelFunc()
80
81 user := *GetUser("cancel_transaction", Config{})
82 DB.Create(&user)
83
84 err := DB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
85 var result User
86 tx.First(&result, user.ID)
87 return nil
88 })
89
90 if err == nil {
91 t.Fatalf("Transaction should get error when using cancelled context")
92 }
93}
94
95func TestTransactionWithBlock(t *testing.T) {
96 assertPanic := func(f func()) {

Callers

nothing calls this directly

Calls 5

GetUserFunction · 0.85
TransactionMethod · 0.80
WithContextMethod · 0.80
CreateMethod · 0.65
FirstMethod · 0.65

Tested by

no test coverage detected