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

Function ensureConnValid

pgconn/helper_test.go:26–36  ·  view source on GitHub ↗

Do a simple query to ensure the connection is still usable

(t *testing.T, pgConn *pgconn.PgConn)

Source from the content-addressed store, hash-verified

24
25// Do a simple query to ensure the connection is still usable
26func ensureConnValid(t *testing.T, pgConn *pgconn.PgConn) {
27 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
28 result := pgConn.ExecParams(ctx, "select generate_series(1,$1)", [][]byte{[]byte("3")}, nil, nil, nil).Read()
29 cancel()
30
31 require.Nil(t, result.Err)
32 assert.Equal(t, 3, len(result.Rows))
33 assert.Equal(t, "1", string(result.Rows[0][0]))
34 assert.Equal(t, "2", string(result.Rows[1][0]))
35 assert.Equal(t, "3", string(result.Rows[2][0]))
36}

Calls 2

ReadMethod · 0.45
ExecParamsMethod · 0.45

Tested by

no test coverage detected