File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -167,8 +167,6 @@ async def _acquire(self):
167
167
assert not conn .closed , conn
168
168
assert conn not in self ._used , (conn , self ._used )
169
169
self ._used .add (conn )
170
- if self ._on_connect is not None :
171
- await self ._on_connect (conn )
172
170
return conn
173
171
else :
174
172
await self ._cond .wait ()
@@ -197,6 +195,8 @@ async def _fill_free_pool(self, override_min):
197
195
enable_uuid = self ._enable_uuid ,
198
196
echo = self ._echo ,
199
197
** self ._conn_kwargs )
198
+ if self ._on_connect is not None :
199
+ await self ._on_connect (conn )
200
200
# raise exception if pool is closing
201
201
self ._free .append (conn )
202
202
self ._cond .notify ()
@@ -215,6 +215,8 @@ async def _fill_free_pool(self, override_min):
215
215
enable_uuid = self ._enable_uuid ,
216
216
echo = self ._echo ,
217
217
** self ._conn_kwargs )
218
+ if self ._on_connect is not None :
219
+ await self ._on_connect (conn )
218
220
# raise exception if pool is closing
219
221
self ._free .append (conn )
220
222
self ._cond .notify ()
Original file line number Diff line number Diff line change @@ -761,7 +761,7 @@ The basic usage is::
761
761
762
762
:param bool echo: executed log SQL queryes (disabled by default).
763
763
764
- :param on_connect: a *callback coroutine * executed at once for every
764
+ :param on_connect: a *callback coroutine * executed once for every
765
765
created connection. May be used for setting up connection level
766
766
state like client encoding etc.
767
767
Original file line number Diff line number Diff line change @@ -546,20 +546,28 @@ async def test_close_running_cursor(create_pool):
546
546
await cur .execute ('SELECT pg_sleep(10)' )
547
547
548
548
549
- async def test_pool_on_connect (create_pool ):
550
- called = False
549
+ @pytest .mark .parametrize ('pool_minsize' , [0 , 1 ])
550
+ async def test_pool_on_connect (create_pool , pool_minsize ):
551
+ cb_called_times = 0
551
552
552
553
async def cb (connection ):
553
- nonlocal called
554
+ nonlocal cb_called_times
554
555
async with connection .cursor () as cur :
555
556
await cur .execute ('SELECT 1' )
556
557
data = await cur .fetchall ()
557
558
assert [(1 ,)] == data
558
- called = True
559
+ cb_called_times += 1
559
560
560
- pool = await create_pool (on_connect = cb )
561
+ pool = await create_pool (
562
+ minsize = pool_minsize ,
563
+ maxsize = 1 ,
564
+ on_connect = cb
565
+ )
566
+
567
+ with (await pool .cursor ()) as cur :
568
+ await cur .execute ('SELECT 1' )
561
569
562
570
with (await pool .cursor ()) as cur :
563
571
await cur .execute ('SELECT 1' )
564
572
565
- assert called
573
+ assert cb_called_times == 1
You can’t perform that action at this time.
0 commit comments