MCPcopy
hub / github.com/jackc/pgx / ensureConnValid

Function ensureConnValid

helper_test.go:65–91  ·  view source on GitHub ↗

Do a simple query to ensure the connection is still usable

(t testing.TB, conn *pgx.Conn)

Source from the content-addressed store, hash-verified

63
64// Do a simple query to ensure the connection is still usable
65func ensureConnValid(t testing.TB, conn *pgx.Conn) {
66 var sum, rowCount int32
67
68 rows, err := conn.Query(context.Background(), "select generate_series(1,$1)", 10)
69 if err != nil {
70 t.Fatalf("conn.Query failed: %v", err)
71 }
72 defer rows.Close()
73
74 for rows.Next() {
75 var n int32
76 rows.Scan(&n)
77 sum += n
78 rowCount++
79 }
80
81 if rows.Err() != nil {
82 t.Fatalf("conn.Query failed: %v", rows.Err())
83 }
84
85 if rowCount != 10 {
86 t.Error("Select called onDataRow wrong number of times")
87 }
88 if sum != 55 {
89 t.Error("Wrong values returned")
90 }
91}
92
93func assertConfigsEqual(t *testing.T, expected, actual *pgx.ConnConfig, testName string) {
94 if !assert.NotNil(t, expected) {

Calls 6

QueryMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected