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

Function TestPoolAfterConnect

pgxpool/pool_test.go:328–350  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

326}
327
328func TestPoolAfterConnect(t *testing.T) {
329 t.Parallel()
330
331 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
332 defer cancel()
333
334 config, err := pgxpool.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
335 require.NoError(t, err)
336
337 config.AfterConnect = func(ctx context.Context, c *pgx.Conn) error {
338 _, err := c.Prepare(ctx, "ps1", "select 1")
339 return err
340 }
341
342 db, err := pgxpool.NewWithConfig(ctx, config)
343 require.NoError(t, err)
344 defer db.Close()
345
346 var n int32
347 err = db.QueryRow(ctx, "ps1").Scan(&n)
348 require.NoError(t, err)
349 assert.EqualValues(t, 1, n)
350}
351
352func TestPoolBeforeAcquire(t *testing.T) {
353 t.Parallel()

Callers

nothing calls this directly

Calls 6

ParseConfigFunction · 0.92
NewWithConfigFunction · 0.92
PrepareMethod · 0.65
CloseMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected