MCPcopy
hub / github.com/psycopg/psycopg / test_reconnect

Function test_reconnect

tests/pool/test_pool_async.py:488–521  ·  view source on GitHub ↗
(proxy, caplog, monkeypatch)

Source from the content-addressed store, hash-verified

486@pytest.mark.slow
487@pytest.mark.timing
488async def test_reconnect(proxy, caplog, monkeypatch):
489 caplog.set_level(logging.WARNING, logger="psycopg.pool")
490
491 assert pool.base.AttemptWithBackoff.INITIAL_DELAY == 1.0
492 assert pool.base.AttemptWithBackoff.DELAY_JITTER == 0.1
493 monkeypatch.setattr(pool.base.AttemptWithBackoff, "INITIAL_DELAY", 0.1)
494 monkeypatch.setattr(pool.base.AttemptWithBackoff, "DELAY_JITTER", 0.0)
495
496 caplog.clear()
497 proxy.start()
498 async with pool.AsyncConnectionPool(proxy.client_dsn, min_size=1) as p:
499 await p.wait(2.0)
500 proxy.stop()
501
502 with pytest.raises(psycopg.OperationalError):
503 async with p.connection() as conn:
504 await conn.execute("select 1")
505
506 await asleep(1.0)
507 proxy.start()
508 await p.wait()
509
510 async with p.connection() as conn:
511 await conn.execute("select 1")
512
513 assert "BAD" in caplog.messages[0]
514 times = [rec.created for rec in caplog.records]
515 assert times[1] - times[0] < 0.05
516 deltas = [times[i + 1] - times[i] for i in range(1, len(times) - 1)]
517 assert len(deltas) == 3
518 want = 0.1
519 for delta in deltas:
520 assert delta == pytest.approx(want, 0.1), deltas
521 want *= 2
522
523
524@pytest.mark.slow

Callers

nothing calls this directly

Calls 7

asleepFunction · 0.50
clearMethod · 0.45
startMethod · 0.45
waitMethod · 0.45
stopMethod · 0.45
connectionMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…