Skip to content

Commit

Permalink
fix: terminate method idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
kalombos committed May 28, 2024
1 parent c7707f3 commit fa356b8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.3'

services:
postgres:
image: postgres
Expand Down
5 changes: 3 additions & 2 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ async def create(self):
async def terminate(self):
"""Terminate all pool connections.
"""
self.pool.terminate()
await self.pool.wait_closed()
if self.pool is not None:
self.pool.terminate()
await self.pool.wait_closed()


############
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ async def db(request):
)

# MANAGERS fixtures will be removed in v1.0.0
# TODO add manager prefix to fixtures
postgres_only = pytest.mark.parametrize(
"manager", PG_DBS, indirect=["manager"]
)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ async def test_is_connected(db):

await db.aio_close()
assert db.is_connected is False


@dbs_all
async def test_aio_close_idempotent(db):
assert db.is_connected is False

await db.aio_close()
assert db.is_connected is False

await db.aio_close()
assert db.is_connected is False

0 comments on commit fa356b8

Please sign in to comment.