@pytest.mark.slow
@pytest.mark.timing
-def test_stats_usage(dsn):
+def test_stats_usage(dsn, retries):
def worker(n):
try:
with p.connection(timeout=0.3) as conn:
except pool.PoolTimeout:
pass
- with pool.ConnectionPool(dsn, min_size=3) as p:
- p.wait(2.0)
+ for retry in retries:
+ with retry:
+ with pool.ConnectionPool(dsn, min_size=3) as p:
+ p.wait(2.0)
- ts = [Thread(target=worker, args=(i,)) for i in range(7)]
- [t.start() for t in ts]
- [t.join() for t in ts]
- stats = p.get_stats()
- assert stats["requests_num"] == 7
- assert stats["requests_queued"] == 4
- assert 850 <= stats["requests_wait_ms"] <= 950
- assert stats["requests_errors"] == 1
- assert 1150 <= stats["usage_ms"] <= 1250
- assert stats.get("returns_bad", 0) == 0
+ ts = [Thread(target=worker, args=(i,)) for i in range(7)]
+ [t.start() for t in ts]
+ [t.join() for t in ts]
+ stats = p.get_stats()
+ assert stats["requests_num"] == 7
+ assert stats["requests_queued"] == 4
+ assert 850 <= stats["requests_wait_ms"] <= 950
+ assert stats["requests_errors"] == 1
+ assert 1150 <= stats["usage_ms"] <= 1250
+ assert stats.get("returns_bad", 0) == 0
- with p.connection() as conn:
- conn.close()
- p.wait()
- stats = p.pop_stats()
- assert stats["requests_num"] == 8
- assert stats["returns_bad"] == 1
- with p.connection():
- pass
- assert p.get_stats()["requests_num"] == 1
+ with p.connection() as conn:
+ conn.close()
+ p.wait()
+ stats = p.pop_stats()
+ assert stats["requests_num"] == 8
+ assert stats["returns_bad"] == 1
+ with p.connection():
+ pass
+ assert p.get_stats()["requests_num"] == 1
@pytest.mark.slow
@pytest.mark.slow
@pytest.mark.timing
-async def test_stats_usage(dsn):
+async def test_stats_usage(dsn, retries):
async def worker(n):
try:
async with p.connection(timeout=0.3) as conn:
except pool.PoolTimeout:
pass
- async with pool.AsyncConnectionPool(dsn, min_size=3) as p:
- await p.wait(2.0)
+ async for retry in retries:
+ with retry:
+ async with pool.AsyncConnectionPool(dsn, min_size=3) as p:
+ await p.wait(2.0)
- ts = [create_task(worker(i)) for i in range(7)]
- await asyncio.gather(*ts)
- stats = p.get_stats()
- assert stats["requests_num"] == 7
- assert stats["requests_queued"] == 4
- assert 850 <= stats["requests_wait_ms"] <= 950
- assert stats["requests_errors"] == 1
- assert 1150 <= stats["usage_ms"] <= 1250
- assert stats.get("returns_bad", 0) == 0
+ ts = [create_task(worker(i)) for i in range(7)]
+ await asyncio.gather(*ts)
+ stats = p.get_stats()
+ assert stats["requests_num"] == 7
+ assert stats["requests_queued"] == 4
+ assert 850 <= stats["requests_wait_ms"] <= 950
+ assert stats["requests_errors"] == 1
+ assert 1150 <= stats["usage_ms"] <= 1250
+ assert stats.get("returns_bad", 0) == 0
- async with p.connection() as conn:
- await conn.close()
- await p.wait()
- stats = p.pop_stats()
- assert stats["requests_num"] == 8
- assert stats["returns_bad"] == 1
- async with p.connection():
- pass
- assert p.get_stats()["requests_num"] == 1
+ async with p.connection() as conn:
+ await conn.close()
+ await p.wait()
+ stats = p.pop_stats()
+ assert stats["requests_num"] == 8
+ assert stats["returns_bad"] == 1
+ async with p.connection():
+ pass
+ assert p.get_stats()["requests_num"] == 1
@pytest.mark.slow
@pytest.mark.slow
-def test_concurrent_execution(dsn):
+def test_concurrent_execution(dsn, retries):
def worker():
cnn = psycopg.connect(dsn)
cur = cnn.cursor()
cur.close()
cnn.close()
- t1 = threading.Thread(target=worker)
- t2 = threading.Thread(target=worker)
- t0 = time.time()
- t1.start()
- t2.start()
- t1.join()
- t2.join()
- assert time.time() - t0 < 0.8, "something broken in concurrency"
+ for retry in retries:
+ with retry:
+ t1 = threading.Thread(target=worker)
+ t2 = threading.Thread(target=worker)
+ t0 = time.time()
+ t1.start()
+ t2.start()
+ t1.join()
+ t2.join()
+ assert time.time() - t0 < 0.8, "something broken in concurrency"
@pytest.mark.slow
@pytest.mark.slow
-async def test_concurrent_execution(dsn):
+async def test_concurrent_execution(dsn, retries):
async def worker():
cnn = await psycopg.AsyncConnection.connect(dsn)
cur = cnn.cursor()
await cur.close()
await cnn.close()
- workers = [worker(), worker()]
- t0 = time.time()
- await asyncio.gather(*workers)
- assert time.time() - t0 < 0.8, "something broken in concurrency"
+ async for retry in retries:
+ with retry:
+ workers = [worker(), worker()]
+ t0 = time.time()
+ await asyncio.gather(*workers)
+ assert time.time() - t0 < 0.8, "something broken in concurrency"
@pytest.mark.slow