"task run %s failed: %s: %s", task, e.__class__.__name__, e
)
- async def wait_ready(self, timeout: float = 30.0) -> None:
+ async def wait(self, timeout: float = 30.0) -> None:
"""
Wait for the pool to be full after init.
)
async with self._lock:
+ assert self._pool_full_event
self._pool_full_event = None
@asynccontextmanager
for i in range(len(self._workers)):
self.run_task(StopWorker(self))
- def wait_ready(self, timeout: float = 30.0) -> None:
+ def wait(self, timeout: float = 30.0) -> None:
"""
Wait for the pool to be full after init.
)
with self._lock:
+ assert self._pool_full_event
self._pool_full_event = None
@contextmanager
t0 = time()
with pool.ConnectionPool(dsn, minconn=5, num_workers=2) as p:
- p.wait_ready(1.0)
+ p.wait(1.0)
want_times = [0.1, 0.1, 0.2, 0.2, 0.3]
assert len(times) == len(want_times)
for got, want in zip(times, want_times):
delay_connection(monkeypatch, 0.1)
with pytest.raises(pool.PoolTimeout):
with pool.ConnectionPool(dsn, minconn=4, num_workers=1) as p:
- p.wait_ready(0.3)
+ p.wait(0.3)
with pool.ConnectionPool(dsn, minconn=4, num_workers=1) as p:
- p.wait_ready(0.5)
+ p.wait(0.5)
with pool.ConnectionPool(dsn, minconn=4, num_workers=2) as p:
- p.wait_ready(0.3)
- p.wait_ready(0.0001) # idempotent
+ p.wait(0.3)
+ p.wait(0.0001) # idempotent
@pytest.mark.slow
with pool.ConnectionPool(
proxy.client_dsn, minconn=1, num_workers=1
) as p:
- p.wait_ready(0.2)
+ p.wait(0.2)
with pool.ConnectionPool(proxy.client_dsn, minconn=1, num_workers=1) as p:
sleep(0.5)
with pool.ConnectionPool(minconn=1, configure=configure) as p:
with pytest.raises(pool.PoolTimeout):
- p.wait_ready(timeout=0.5)
+ p.wait(timeout=0.5)
assert caplog.records
assert "WAT" in caplog.records[0].message
with p.connection() as conn:
conn.execute("select 1")
- p.wait_ready()
+ p.wait()
ref = weakref.ref(p)
del p
assert not ref()
with pool.ConnectionPool(
dsn, minconn=2, maxconn=4, num_workers=3
) as p:
- p.wait_ready(1.0)
+ p.wait(1.0)
results = []
ts = [Thread(target=worker, args=(i,)) for i in range(6)]
conn.execute("select pg_sleep(0.1)")
with pool.ConnectionPool(dsn, minconn=2, maxconn=4, max_idle=0.2) as p:
- p.wait_ready(5.0)
+ p.wait(5.0)
assert p.max_idle == 0.2
ts = [Thread(target=worker, args=(i,)) for i in range(4)]
proxy.start()
with pool.ConnectionPool(proxy.client_dsn, minconn=1) as p:
- p.wait_ready(2.0)
+ p.wait(2.0)
proxy.stop()
with pytest.raises(psycopg3.OperationalError):
sleep(1.0)
proxy.start()
- p.wait_ready()
+ p.wait()
with p.connection() as conn:
conn.execute("select 1")
reconnect_timeout=1.0,
reconnect_failed=failed,
) as p:
- p.wait_ready(2.0)
+ p.wait(2.0)
proxy.stop()
with pytest.raises(psycopg3.OperationalError):
def test_check(dsn, caplog):
caplog.set_level(logging.WARNING, logger="psycopg3.pool")
with pool.ConnectionPool(dsn, minconn=4) as p:
- p.wait_ready(1.0)
+ p.wait(1.0)
with p.connection() as conn:
pid = conn.pgconn.backend_pid
- p.wait_ready(1.0)
+ p.wait(1.0)
pids = set(conn.pgconn.backend_pid for conn in p._pool)
assert pid in pids
conn.close()
assert len(caplog.records) == 0
p.check()
assert len(caplog.records) == 1
- p.wait_ready(1.0)
+ p.wait(1.0)
pids2 = set(conn.pgconn.backend_pid for conn in p._pool)
assert len(pids & pids2) == 3
assert pid not in pids2
async with pool.AsyncConnectionPool(
dsn, minconn=5, num_workers=2
) as p:
- await p.wait_ready(1.0)
+ await p.wait(1.0)
want_times = [0.1, 0.1, 0.2, 0.2, 0.3]
assert len(times) == len(want_times)
for got, want in zip(times, want_times):
async with pool.AsyncConnectionPool(
dsn, minconn=4, num_workers=1
) as p:
- await p.wait_ready(0.3)
+ await p.wait(0.3)
async with pool.AsyncConnectionPool(dsn, minconn=4, num_workers=1) as p:
- await p.wait_ready(0.5)
+ await p.wait(0.5)
async with pool.AsyncConnectionPool(dsn, minconn=4, num_workers=2) as p:
- await p.wait_ready(0.3)
- await p.wait_ready(0.0001) # idempotent
+ await p.wait(0.3)
+ await p.wait(0.0001) # idempotent
@pytest.mark.slow
async with pool.AsyncConnectionPool(
proxy.client_dsn, minconn=1, num_workers=1
) as p:
- await p.wait_ready(0.2)
+ await p.wait(0.2)
async with pool.AsyncConnectionPool(
proxy.client_dsn, minconn=1, num_workers=1
async with pool.AsyncConnectionPool(minconn=1, configure=configure) as p:
with pytest.raises(pool.PoolTimeout):
- await p.wait_ready(timeout=0.5)
+ await p.wait(timeout=0.5)
assert caplog.records
assert "WAT" in caplog.records[0].message
async with pool.AsyncConnectionPool(
dsn, minconn=2, maxconn=4, num_workers=3
) as p:
- await p.wait_ready(1.0)
+ await p.wait(1.0)
ts = []
results = []
async with pool.AsyncConnectionPool(
dsn, minconn=2, maxconn=4, max_idle=0.2
) as p:
- await p.wait_ready(5.0)
+ await p.wait(5.0)
assert p.max_idle == 0.2
ts = [create_task(worker(i)) for i in range(4)]
proxy.start()
async with pool.AsyncConnectionPool(proxy.client_dsn, minconn=1) as p:
- await p.wait_ready(2.0)
+ await p.wait(2.0)
proxy.stop()
with pytest.raises(psycopg3.OperationalError):
await asyncio.sleep(1.0)
proxy.start()
- await p.wait_ready()
+ await p.wait()
async with p.connection() as conn:
await conn.execute("select 1")
reconnect_timeout=1.0,
reconnect_failed=failed,
) as p:
- await p.wait_ready(2.0)
+ await p.wait(2.0)
proxy.stop()
with pytest.raises(psycopg3.OperationalError):
async def test_check(dsn, caplog):
caplog.set_level(logging.WARNING, logger="psycopg3.pool")
async with pool.AsyncConnectionPool(dsn, minconn=4) as p:
- await p.wait_ready(1.0)
+ await p.wait(1.0)
async with p.connection() as conn:
pid = conn.pgconn.backend_pid
- await p.wait_ready(1.0)
+ await p.wait(1.0)
pids = set(conn.pgconn.backend_pid for conn in p._pool)
assert pid in pids
await conn.close()
assert len(caplog.records) == 0
await p.check()
assert len(caplog.records) == 1
- await p.wait_ready(1.0)
+ await p.wait(1.0)
pids2 = set(conn.pgconn.backend_pid for conn in p._pool)
assert len(pids & pids2) == 3
assert pid not in pids2