(t *testing.T)
| 674 | } |
| 675 | |
| 676 | func 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 | |
| 712 | func TestPoolBackgroundChecksMinConns(t *testing.T) { |
| 713 | t.Parallel() |
nothing calls this directly
no test coverage detected