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

Function TestConnReleaseClosesBusyConn

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

Source from the content-addressed store, hash-verified

615}
616
617func TestConnReleaseClosesBusyConn(t *testing.T) {
618 t.Parallel()
619
620 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
621 defer cancel()
622
623 db, err := pgxpool.New(ctx, os.Getenv("PGX_TEST_DATABASE"))
624 require.NoError(t, err)
625 defer db.Close()
626
627 c, err := db.Acquire(ctx)
628 require.NoError(t, err)
629
630 _, err = c.Query(ctx, "select generate_series(1,10)")
631 require.NoError(t, err)
632
633 c.Release()
634 waitForReleaseToComplete()
635
636 // wait for the connection to actually be destroyed
637 for range 1000 {
638 if db.Stat().TotalConns() == 0 {
639 break
640 }
641 time.Sleep(time.Millisecond)
642 }
643
644 stats := db.Stat()
645 assert.EqualValues(t, 0, stats.TotalConns())
646}
647
648func TestPoolBackgroundChecksMaxConnLifetime(t *testing.T) {
649 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
waitForReleaseToCompleteFunction · 0.85
AcquireMethod · 0.80
ReleaseMethod · 0.80
TotalConnsMethod · 0.80
StatMethod · 0.80
CloseMethod · 0.65
QueryMethod · 0.65

Tested by

no test coverage detected