(t *testing.T)
| 206 | } |
| 207 | |
| 208 | func TestPoolAcquireChecksIdleConnsWithShouldPing(t *testing.T) { |
| 209 | t.Parallel() |
| 210 | |
| 211 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 212 | defer cancel() |
| 213 | |
| 214 | controllerConn, err := pgx.Connect(ctx, os.Getenv("PGX_TEST_DATABASE")) |
| 215 | require.NoError(t, err) |
| 216 | defer controllerConn.Close(ctx) |
| 217 | |
| 218 | config, err := pgxpool.ParseConfig(os.Getenv("PGX_TEST_DATABASE")) |
| 219 | require.NoError(t, err) |
| 220 | |
| 221 | // Replace the default ShouldPing func |
| 222 | var shouldPingLastCalledWith *pgxpool.ShouldPingParams |
| 223 | config.ShouldPing = func(ctx context.Context, params pgxpool.ShouldPingParams) bool { |
| 224 | shouldPingLastCalledWith = ¶ms |
| 225 | return false |
| 226 | } |
| 227 | |
| 228 | pool, err := pgxpool.NewWithConfig(ctx, config) |
| 229 | require.NoError(t, err) |
| 230 | defer pool.Close() |
| 231 | |
| 232 | c, err := pool.Acquire(ctx) |
| 233 | require.NoError(t, err) |
| 234 | c.Release() |
| 235 | |
| 236 | time.Sleep(time.Millisecond * 200) |
| 237 | |
| 238 | c, err = pool.Acquire(ctx) |
| 239 | require.NoError(t, err) |
| 240 | conn := c.Conn() |
| 241 | |
| 242 | require.NotNil(t, shouldPingLastCalledWith) |
| 243 | assert.Equal(t, conn, shouldPingLastCalledWith.Conn) |
| 244 | assert.InDelta(t, time.Millisecond*200, shouldPingLastCalledWith.IdleDuration, float64(time.Millisecond*100)) |
| 245 | |
| 246 | c.Release() |
| 247 | } |
| 248 | |
| 249 | // https://github.com/jackc/pgx/issues/2379 |
| 250 | func TestPoolAcquireWithMaxConnsEqualsMaxInt32(t *testing.T) { |
nothing calls this directly
no test coverage detected