11import asyncio
22
3- from unittest import TestCase
4-
53from ..base import DBTestCase , postgres_only
64from ..example_project .tables import Manager
75
86
97@postgres_only
108class 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