MCPcopy
hub / github.com/go-sql-driver/mysql / TestReuseClosedConnection

Function TestReuseClosedConnection

driver_test.go:1523–1559  ·  driver_test.go::TestReuseClosedConnection
(t *testing.T)

Source from the content-addressed store, hash-verified

1521}
1522
1523func TestReuseClosedConnection(t *testing.T) {
1524 // this test does not use sql.database, it uses the driver directly
1525 if !available {
1526 t.Skipf("MySQL server not running on %s", netAddr)
1527 }
1528
1529 md := &MySQLDriver{}
1530 conn, err := md.Open(dsn)
1531 if err != nil {
1532 t.Fatalf("error connecting: %s", err.Error())
1533 }
1534 stmt, err := conn.Prepare("DO 1")
1535 if err != nil {
1536 t.Fatalf("error preparing statement: %s", err.Error())
1537 }
1538 //lint:ignore SA1019 this is a test
1539 _, err = stmt.Exec(nil)
1540 if err != nil {
1541 t.Fatalf("error executing statement: %s", err.Error())
1542 }
1543 err = conn.Close()
1544 if err != nil {
1545 t.Fatalf("error closing connection: %s", err.Error())
1546 }
1547
1548 defer func() {
1549 if err := recover(); err != nil {
1550 t.Errorf("panic after reusing a closed connection: %v", err)
1551 }
1552 }()
1553 //lint:ignore SA1019 this is a test
1554 _, err = stmt.Exec(nil)
1555 if err != nil && err != driver.ErrBadConn {
1556 t.Errorf("unexpected error '%s', expected '%s'",
1557 err.Error(), driver.ErrBadConn.Error())
1558 }
1559}
1560
1561func TestCharset(t *testing.T) {
1562 if !available {

Callers

nothing calls this directly

Calls 5

OpenMethod · 0.95
PrepareMethod · 0.80
ErrorMethod · 0.45
ExecMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected