DBPoolClone returns a disposable clone of DBPool. Share resources by using DBPool when possible, but this is useless for areas like stress tests where context cancellations are likely to end up closing the pool. Unlike DBPool, adds a test cleanup hook that closes the pool after run.
(ctx context.Context, tb testing.TB)
| 86 | // |
| 87 | // Unlike DBPool, adds a test cleanup hook that closes the pool after run. |
| 88 | func DBPoolClone(ctx context.Context, tb testing.TB) *pgxpool.Pool { |
| 89 | tb.Helper() |
| 90 | |
| 91 | dbPool := DBPool(ctx, tb) |
| 92 | |
| 93 | config := dbPool.Config() |
| 94 | config.MaxConns = 4 // dramatically reduce max allowed conns for clones so we they don't clobber the database server |
| 95 | |
| 96 | var err error |
| 97 | dbPool, err = pgxpool.NewWithConfig(ctx, config) |
| 98 | require.NoError(tb, err) |
| 99 | |
| 100 | tb.Cleanup(dbPool.Close) |
| 101 | |
| 102 | return dbPool |
| 103 | } |
| 104 | |
| 105 | // Gets an SQLite test directory at project root so it's invariant of which |
| 106 | // package tests are being run in. |
searching dependent graphs…