MCPcopy
hub / github.com/psycopg/psycopg / test_queue_timeout_override

Function test_queue_timeout_override

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

Source from the content-addressed store, hash-verified

293@pytest.mark.timing
294@pytest.mark.crdb_skip("backend pid")
295async def test_queue_timeout_override(pool_cls, dsn):
296 async def worker(n):
297 t0 = time()
298 timeout = 0.25 if n == 3 else None
299 try:
300 async with p.connection(timeout=timeout) as conn:
301 await conn.execute("select pg_sleep(0.2)")
302 pid = conn.info.backend_pid
303 except pool.PoolTimeout as e:
304 t1 = time()
305 errors.append((n, t1 - t0, e))
306 else:
307 t1 = time()
308 results.append((n, t1 - t0, pid))
309
310 results: list[tuple[int, float, int]] = []
311 errors: list[tuple[int, float, Exception]] = []
312
313 async with pool_cls(
314 dsn, min_size=min_size(pool_cls, 2), max_size=2, timeout=0.1
315 ) as p:
316 ts = [spawn(worker, args=(i,)) for i in range(4)]
317 await gather(*ts)
318
319 assert len(results) == 3
320 assert len(errors) == 1
321 for e in errors:
322 assert 0.1 < e[1] < 0.15
323
324
325@pytest.mark.crdb_skip("backend pid")

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