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

Function TestPoolBackgroundChecksMaxConnIdleTime

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

Source from the content-addressed store, hash-verified

674}
675
676func TestPoolBackgroundChecksMaxConnIdleTime(t *testing.T) {
677 t.Parallel()
678
679 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
680 defer cancel()
681
682 config, err := pgxpool.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
683 require.NoError(t, err)
684
685 config.MaxConnLifetime = 1 * time.Minute
686 config.MaxConnIdleTime = 100 * time.Millisecond
687 config.HealthCheckPeriod = 150 * time.Millisecond
688
689 db, err := pgxpool.NewWithConfig(ctx, config)
690 require.NoError(t, err)
691 defer db.Close()
692
693 c, err := db.Acquire(ctx)
694 require.NoError(t, err)
695 c.Release()
696 time.Sleep(config.HealthCheckPeriod)
697
698 for range 1000 {
699 if db.Stat().TotalConns() == 0 {
700 break
701 }
702 time.Sleep(time.Millisecond)
703 }
704
705 stats := db.Stat()
706 assert.EqualValues(t, 0, stats.TotalConns())
707 assert.EqualValues(t, 1, stats.MaxIdleDestroyCount())
708 assert.EqualValues(t, 0, stats.MaxLifetimeDestroyCount())
709 assert.EqualValues(t, 1, stats.NewConnsCount())
710}
711
712func TestPoolBackgroundChecksMinConns(t *testing.T) {
713 t.Parallel()

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected