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

Function TestPoolAcquireAndConnHijack

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

Source from the content-addressed store, hash-verified

125}
126
127func TestPoolAcquireAndConnHijack(t *testing.T) {
128 t.Parallel()
129
130 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
131 defer cancel()
132
133 pool, err := pgxpool.New(ctx, os.Getenv("PGX_TEST_DATABASE"))
134 require.NoError(t, err)
135 defer pool.Close()
136
137 c, err := pool.Acquire(ctx)
138 require.NoError(t, err)
139
140 connsBeforeHijack := pool.Stat().TotalConns()
141
142 conn := c.Hijack()
143 defer conn.Close(ctx)
144
145 connsAfterHijack := pool.Stat().TotalConns()
146 require.Equal(t, connsBeforeHijack-1, connsAfterHijack)
147
148 var n int32
149 err = conn.QueryRow(ctx, `select 1`).Scan(&n)
150 require.NoError(t, err)
151 require.Equal(t, int32(1), n)
152}
153
154func TestPoolAcquireChecksIdleConns(t *testing.T) {
155 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
AcquireMethod · 0.80
TotalConnsMethod · 0.80
StatMethod · 0.80
CloseMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65
HijackMethod · 0.45

Tested by

no test coverage detected