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

Function TestPreparedStmtDeadlock

tests/prepared_stmt_test.go:153–186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

151}
152
153func TestPreparedStmtDeadlock(t *testing.T) {
154 tx, err := OpenTestConnection(&gorm.Config{})
155 AssertEqual(t, err, nil)
156
157 sqlDB, _ := tx.DB()
158 sqlDB.SetMaxOpenConns(1)
159
160 tx = tx.Session(&gorm.Session{PrepareStmt: true})
161
162 wg := sync.WaitGroup{}
163 for i := 0; i < 100; i++ {
164 wg.Add(1)
165 go func() {
166 user := User{Name: "jinzhu"}
167 tx.Create(&user)
168
169 var result User
170 tx.First(&result)
171 wg.Done()
172 }()
173 }
174 wg.Wait()
175
176 conn, ok := tx.ConnPool.(*gorm.PreparedStmtDB)
177 AssertEqual(t, ok, true)
178 AssertEqual(t, len(conn.Stmts.Keys()), 2)
179 for _, stmt := range conn.Stmts.Keys() {
180 if stmt == "" {
181 t.Fatalf("stmt cannot bee nil")
182 }
183 }
184
185 AssertEqual(t, sqlDB.Stats().InUse, 0)
186}
187
188func TestPreparedStmtInTransaction(t *testing.T) {
189 user := User{Name: "jinzhu"}

Callers

nothing calls this directly

Calls 8

OpenTestConnectionFunction · 0.85
DBMethod · 0.80
SessionMethod · 0.80
AddMethod · 0.80
CreateMethod · 0.65
FirstMethod · 0.65
KeysMethod · 0.65
AssertEqualFunction · 0.50

Tested by

no test coverage detected