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

Function TestPreparedStmtClose

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

Source from the content-addressed store, hash-verified

202}
203
204func TestPreparedStmtClose(t *testing.T) {
205 tx := DB.Session(&gorm.Session{PrepareStmt: true})
206
207 user := *GetUser("prepared_stmt_close", Config{})
208 tx = tx.Create(&user)
209
210 pdb, ok := tx.ConnPool.(*gorm.PreparedStmtDB)
211 if !ok {
212 t.Fatalf("should assign PreparedStatement Manager back to database when using PrepareStmt mode")
213 }
214
215 pdb.Mux.Lock()
216 if len(pdb.Stmts.Keys()) == 0 {
217 pdb.Mux.Unlock()
218 t.Fatalf("prepared stmt can not be empty")
219 }
220 pdb.Mux.Unlock()
221
222 pdb.Close()
223 pdb.Mux.Lock()
224 defer pdb.Mux.Unlock()
225 if len(pdb.Stmts.Keys()) != 0 {
226 t.Fatalf("prepared stmt should be empty")
227 }
228}
229
230func isUsingClosedConnError(err error) bool {
231 // https://github.com/golang/go/blob/e705a2d16e4ece77e08e80c168382cdb02890f5b/src/database/sql/sql.go#L2717

Callers

nothing calls this directly

Calls 5

GetUserFunction · 0.85
SessionMethod · 0.80
CreateMethod · 0.65
KeysMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected