(t *testing.T)
| 491 | } |
| 492 | |
| 493 | func TestPoolBeforeClose(t *testing.T) { |
| 494 | t.Parallel() |
| 495 | |
| 496 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 497 | defer cancel() |
| 498 | |
| 499 | func() { |
| 500 | pool, err := pgxpool.New(ctx, os.Getenv("PGX_TEST_DATABASE")) |
| 501 | require.NoError(t, err) |
| 502 | defer pool.Close() |
| 503 | }() |
| 504 | |
| 505 | config, err := pgxpool.ParseConfig(os.Getenv("PGX_TEST_DATABASE")) |
| 506 | require.NoError(t, err) |
| 507 | |
| 508 | connPIDs := make(chan uint32, 5) |
| 509 | config.BeforeClose = func(c *pgx.Conn) { |
| 510 | connPIDs <- c.PgConn().PID() |
| 511 | } |
| 512 | |
| 513 | db, err := pgxpool.NewWithConfig(ctx, config) |
| 514 | require.NoError(t, err) |
| 515 | defer db.Close() |
| 516 | |
| 517 | acquiredPIDs := make([]uint32, 0, 5) |
| 518 | closedPIDs := make([]uint32, 0, 5) |
| 519 | for range 5 { |
| 520 | conn, err := db.Acquire(ctx) |
| 521 | assert.NoError(t, err) |
| 522 | acquiredPIDs = append(acquiredPIDs, conn.Conn().PgConn().PID()) |
| 523 | conn.Release() |
| 524 | db.Reset() |
| 525 | closedPIDs = append(closedPIDs, <-connPIDs) |
| 526 | } |
| 527 | |
| 528 | assert.ElementsMatch(t, acquiredPIDs, closedPIDs) |
| 529 | } |
| 530 | |
| 531 | func TestPoolAcquireAllIdle(t *testing.T) { |
| 532 | t.Parallel() |
nothing calls this directly
no test coverage detected