The flow where we set _pool = None or _pool = self is a bit complex.
Make sure we don't mess it up.
def worker(n):
t0 = time()
with p.connection() as conn:
+ assert conn._pool is p
conn.execute("select pg_sleep(0.2)")
pid = conn.info.backend_pid
t1 = time()
async def worker(n):
t0 = time()
async with p.connection() as conn:
+ assert conn._pool is p
await conn.execute("select pg_sleep(0.2)")
pid = conn.info.backend_pid
t1 = time()
cur = conn.execute("show timezone")
assert cur.fetchone() == ("UTC",)
pids.append(conn.info.backend_pid)
+ assert conn._pool is p
with pool.NullConnectionPool(dsn, max_size=1, reset=reset) as p:
with p.connection() as conn:
assert resets == 0
conn.execute("set timezone to '+2:00'")
pids.append(conn.info.backend_pid)
+ assert conn._pool is p
gather(t)
p.wait()
cur = await conn.execute("show timezone")
assert (await cur.fetchone()) == ("UTC",)
pids.append(conn.info.backend_pid)
+ assert conn._pool is p
async with pool.AsyncNullConnectionPool(dsn, max_size=1, reset=reset) as p:
async with p.connection() as conn:
assert resets == 0
await conn.execute("set timezone to '+2:00'")
pids.append(conn.info.backend_pid)
+ assert conn._pool is p
await gather(t)
await p.wait()