Skip to content

Commit 28f910a

Browse files
committed
dbutil: even more tests
1 parent 9c3fd28 commit 28f910a

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

dbutil/deadlock_test.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,43 @@ func TestDatabase_Deadlock(t *testing.T) {
8484
db := initTestDB(t)
8585
ctx := context.Background()
8686
_ = db.DoTxn(ctx, nil, func(ctx context.Context) error {
87-
assert.Panics(t, func() {
87+
assert.PanicsWithError(t, dbutil.ErrQueryDeadlock.Error(), func() {
8888
_, _ = db.Exec(context.Background(), "INSERT INTO meow (value) VALUES ('meow 4');")
8989
})
9090
return fmt.Errorf("meow")
9191
})
9292
}
9393

94+
func TestDatabase_Deadlock_Acquire(t *testing.T) {
95+
db := initTestDB(t)
96+
ctx := context.Background()
97+
_ = db.DoTxn(ctx, nil, func(ctx context.Context) error {
98+
assert.PanicsWithError(t, dbutil.ErrAcquireDeadlock.Error(), func() {
99+
_, _ = db.AcquireConn(context.Background())
100+
})
101+
return fmt.Errorf("meow")
102+
})
103+
}
104+
105+
func TestDatabase_Deadlock_Txn(t *testing.T) {
106+
db := initTestDB(t)
107+
ctx := context.Background()
108+
_ = db.DoTxn(ctx, nil, func(ctx context.Context) error {
109+
assert.PanicsWithError(t, dbutil.ErrTransactionDeadlock.Error(), func() {
110+
_ = db.DoTxn(context.Background(), nil, func(ctx context.Context) error {
111+
return nil
112+
})
113+
})
114+
return fmt.Errorf("meow")
115+
})
116+
}
117+
94118
func TestDatabase_Deadlock_Child(t *testing.T) {
95119
db := initTestDB(t)
96120
ctx := context.Background()
97121
childDB := db.Child("", nil, nil)
98122
_ = db.DoTxn(ctx, nil, func(ctx context.Context) error {
99-
assert.Panics(t, func() {
123+
assert.PanicsWithError(t, dbutil.ErrQueryDeadlock.Error(), func() {
100124
_, _ = childDB.Exec(context.Background(), "INSERT INTO meow (value) VALUES ('meow 4');")
101125
})
102126
return fmt.Errorf("meow")
@@ -108,7 +132,7 @@ func TestDatabase_Deadlock_Child2(t *testing.T) {
108132
ctx := context.Background()
109133
childDB := db.Child("", nil, nil)
110134
_ = childDB.DoTxn(ctx, nil, func(ctx context.Context) error {
111-
assert.Panics(t, func() {
135+
assert.PanicsWithError(t, dbutil.ErrQueryDeadlock.Error(), func() {
112136
_, _ = db.Exec(context.Background(), "INSERT INTO meow (value) VALUES ('meow 4');")
113137
})
114138
return fmt.Errorf("meow")

0 commit comments

Comments
 (0)