Skip to content

Commit

Permalink
Don't close prepared stmt for normal db error
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Mar 21, 2024
1 parent 5760388 commit 0d6c534
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/jinzhu/now v1.1.5
github.com/lib/pq v1.10.9
github.com/stretchr/testify v1.9.0
gorm.io/driver/mysql v1.5.5
gorm.io/driver/mysql v1.5.6
gorm.io/driver/postgres v1.5.7
gorm.io/driver/sqlite v1.5.5
gorm.io/driver/sqlserver v1.5.3
Expand Down
27 changes: 0 additions & 27 deletions tests/prepared_stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,6 @@ func TestPreparedStmtDeadlock(t *testing.T) {
AssertEqual(t, sqlDB.Stats().InUse, 0)
}

func TestPreparedStmtError(t *testing.T) {
tx, err := OpenTestConnection(&gorm.Config{})
AssertEqual(t, err, nil)

sqlDB, _ := tx.DB()
sqlDB.SetMaxOpenConns(1)

tx = tx.Session(&gorm.Session{PrepareStmt: true})

wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
// err prepare
tag := Tag{Locale: "zh"}
tx.Table("users").Find(&tag)
wg.Done()
}()
}
wg.Wait()

conn, ok := tx.ConnPool.(*gorm.PreparedStmtDB)
AssertEqual(t, ok, true)
AssertEqual(t, len(conn.Stmts), 0)
AssertEqual(t, sqlDB.Stats().InUse, 0)
}

func TestPreparedStmtInTransaction(t *testing.T) {
user := User{Name: "jinzhu"}

Expand Down

0 comments on commit 0d6c534

Please sign in to comment.