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

Function TestPoolAcquireChecksIdleConnsWithShouldPing

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

Source from the content-addressed store, hash-verified

206}
207
208func TestPoolAcquireChecksIdleConnsWithShouldPing(t *testing.T) {
209 t.Parallel()
210
211 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
212 defer cancel()
213
214 controllerConn, err := pgx.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
215 require.NoError(t, err)
216 defer controllerConn.Close(ctx)
217
218 config, err := pgxpool.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
219 require.NoError(t, err)
220
221 // Replace the default ShouldPing func
222 var shouldPingLastCalledWith *pgxpool.ShouldPingParams
223 config.ShouldPing = func(ctx context.Context, params pgxpool.ShouldPingParams) bool {
224 shouldPingLastCalledWith = &params
225 return false
226 }
227
228 pool, err := pgxpool.NewWithConfig(ctx, config)
229 require.NoError(t, err)
230 defer pool.Close()
231
232 c, err := pool.Acquire(ctx)
233 require.NoError(t, err)
234 c.Release()
235
236 time.Sleep(time.Millisecond * 200)
237
238 c, err = pool.Acquire(ctx)
239 require.NoError(t, err)
240 conn := c.Conn()
241
242 require.NotNil(t, shouldPingLastCalledWith)
243 assert.Equal(t, conn, shouldPingLastCalledWith.Conn)
244 assert.InDelta(t, time.Millisecond*200, shouldPingLastCalledWith.IdleDuration, float64(time.Millisecond*100))
245
246 c.Release()
247}
248
249// https://github.com/jackc/pgx/issues/2379
250func TestPoolAcquireWithMaxConnsEqualsMaxInt32(t *testing.T) {

Callers

nothing calls this directly

Calls 7

ParseConfigFunction · 0.92
NewWithConfigFunction · 0.92
AcquireMethod · 0.80
ReleaseMethod · 0.80
CloseMethod · 0.65
ConnMethod · 0.65
ConnectMethod · 0.45

Tested by

no test coverage detected