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

Function TestPoolBackgroundChecksMaxConnLifetime

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

Source from the content-addressed store, hash-verified

646}
647
648func TestPoolBackgroundChecksMaxConnLifetime(t *testing.T) {
649 t.Parallel()
650
651 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
652 defer cancel()
653
654 config, err := pgxpool.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
655 require.NoError(t, err)
656
657 config.MaxConnLifetime = 100 * time.Millisecond
658 config.HealthCheckPeriod = 100 * time.Millisecond
659
660 db, err := pgxpool.NewWithConfig(ctx, config)
661 require.NoError(t, err)
662 defer db.Close()
663
664 c, err := db.Acquire(ctx)
665 require.NoError(t, err)
666 c.Release()
667 time.Sleep(config.MaxConnLifetime + 500*time.Millisecond)
668
669 stats := db.Stat()
670 assert.EqualValues(t, 0, stats.TotalConns())
671 assert.EqualValues(t, 0, stats.MaxIdleDestroyCount())
672 assert.EqualValues(t, 1, stats.MaxLifetimeDestroyCount())
673 assert.EqualValues(t, 1, stats.NewConnsCount())
674}
675
676func TestPoolBackgroundChecksMaxConnIdleTime(t *testing.T) {
677 t.Parallel()

Callers

nothing calls this directly

Calls 10

ParseConfigFunction · 0.92
NewWithConfigFunction · 0.92
AcquireMethod · 0.80
ReleaseMethod · 0.80
StatMethod · 0.80
TotalConnsMethod · 0.80
MaxIdleDestroyCountMethod · 0.80
NewConnsCountMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected