MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / test_prepare_23_no_stmt_cache_seq

Method test_prepare_23_no_stmt_cache_seq

tests/test_prepare.py:434–462  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

432
433 @tb.with_connection_options(statement_cache_size=0)
434 async def test_prepare_23_no_stmt_cache_seq(self):
435 self.assertEqual(self.con._stmt_cache.get_max_size(), 0)
436
437 async def check_simple():
438 # Run a simple query a few times.
439 self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
440 self.assertEqual(await self.con.fetchval('SELECT 2'), 2)
441 self.assertEqual(await self.con.fetchval('SELECT 1'), 1)
442
443 await check_simple()
444
445 # Run a query that timeouts.
446 with self.assertRaises(asyncio.TimeoutError):
447 await self.con.fetchrow('select pg_sleep(10)', timeout=0.02)
448
449 # Check that we can run new queries after a timeout.
450 await check_simple()
451
452 # Try a cursor/timeout combination. Cursors should always use
453 # named prepared statements.
454 async with self.con.transaction():
455 with self.assertRaises(asyncio.TimeoutError):
456 async for _ in self.con.cursor( # NOQA
457 'select pg_sleep(10)', timeout=0.1):
458 pass
459
460 # Check that we can run queries after a failed cursor
461 # operation.
462 await check_simple()
463
464 @tb.with_connection_options(max_cached_statement_lifetime=142)
465 async def test_prepare_24_max_lifetime(self):

Callers

nothing calls this directly

Calls 4

transactionMethod · 0.80
get_max_sizeMethod · 0.45
fetchrowMethod · 0.45
cursorMethod · 0.45

Tested by

no test coverage detected