MCPcopy
hub / github.com/psycopg/psycopg / test_queue_timeout

Function test_queue_timeout

tests/pool/test_pool_common_async.py:237–263  ·  view source on GitHub ↗
(pool_cls, dsn)

Source from the content-addressed store, hash-verified

235@pytest.mark.timing
236@pytest.mark.crdb_skip("backend pid")
237async def test_queue_timeout(pool_cls, dsn):
238 async def worker(n):
239 t0 = time()
240 try:
241 async with p.connection() as conn:
242 await conn.execute("select pg_sleep(0.2)")
243 pid = conn.info.backend_pid
244 except pool.PoolTimeout as e:
245 t1 = time()
246 errors.append((n, t1 - t0, e))
247 else:
248 t1 = time()
249 results.append((n, t1 - t0, pid))
250
251 results: list[tuple[int, float, int]] = []
252 errors: list[tuple[int, float, Exception]] = []
253
254 async with pool_cls(
255 dsn, min_size=min_size(pool_cls, 2), max_size=2, timeout=0.1
256 ) as p:
257 ts = [spawn(worker, args=(i,)) for i in range(4)]
258 await gather(*ts)
259
260 assert len(results) == 2
261 assert len(errors) == 2
262 for e in errors:
263 assert 0.1 < e[1] < 0.15
264
265
266@pytest.mark.slow

Callers

nothing calls this directly

Calls 4

pool_clsFunction · 0.70
min_sizeFunction · 0.70
spawnFunction · 0.50
gatherFunction · 0.50

Tested by

no test coverage detected