Skip to content

Commit f37d33a

Browse files
committed
testing lots of queries via connection pool
1 parent 67c7229 commit f37d33a

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

docs/src/piccolo/query_clauses/batch.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ You can use ``batch`` clauses with the following queries:
88
* :ref:`Objects`
99
* :ref:`Select`
1010

11-
By default, a query will returns as many rows as you ask it for. The problem is
11+
By default, a query will return as many rows as you ask it for. The problem is
1212
when you have a table containing millions of rows - you might not want to
1313
load them all into memory at once. To get around this, you can batch the
1414
responses.

tests/engine/test_pool.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import asyncio
22

3-
from unittest import TestCase
4-
53
from ..base import DBTestCase, postgres_only
64
from ..example_project.tables import Manager
75

86

97
@postgres_only
108
class TestPool(DBTestCase):
11-
async def create_pool(self):
9+
async def _create_pool(self):
1210
await Manager._meta.db.start_connnection_pool()
1311
await Manager._meta.db.close_connnection_pool()
1412

15-
async def make_queries(self):
13+
async def _make_query(self):
1614
await Manager._meta.db.start_connnection_pool()
1715

1816
await Manager(name="Bob").save().run()
@@ -21,14 +19,34 @@ async def make_queries(self):
2119

2220
await Manager._meta.db.close_connnection_pool()
2321

22+
async def _make_many_queries(self):
23+
await Manager._meta.db.start_connnection_pool()
24+
25+
await Manager(name="Bob").save().run()
26+
27+
async def get_data():
28+
response = await Manager.select().run()
29+
self.assertEqual(response, [{"id": 1, "name": "Bob"}])
30+
31+
await asyncio.gather(*[get_data() for _ in range(500)])
32+
33+
await Manager._meta.db.close_connnection_pool()
34+
2435
def test_creation(self):
2536
"""
2637
Make sure a connection pool can be created.
2738
"""
28-
asyncio.run(self.create_pool())
39+
asyncio.run(self._create_pool())
2940

30-
def test_queries(self):
41+
def test_query(self):
3142
"""
3243
Make several queries using a connection pool.
3344
"""
34-
asyncio.run(self.make_queries())
45+
asyncio.run(self._make_query())
46+
47+
def test_many_queries(self):
48+
"""
49+
Make sure the connection pool is working correctly, and we don't
50+
exceed a connection limit - queries should queue, then succeed.
51+
"""
52+
asyncio.run(self._make_many_queries())

0 commit comments

Comments
 (0)