Skip to content

Commit

Permalink
Add provisional test to understand proper closeing of db sessions (ref
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Apr 28, 2023
1 parent 8a415c4 commit 9b77a10
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,37 @@ async def test_sync_db(db_sync, db):
task_list = res.scalars().all()
assert len(task_list) == 1
assert task_list[0].name == "mytask"


async def test_sync_db_close(db_sync, db):
"""
This test is used as an example to show that the commit() method is not
enough to fully close a db_sync connection.
"""

from fractal_server.app.models.task import Task
from fractal_server.app.db import DB

db.add(
Task(
name="mytask",
input_type="image",
output_type="zarr",
command="cmd",
source="/source",
)
)
await db.commit()
await db.close()

new_db_sync = next(DB.get_sync_db())
task = new_db_sync.get(Task, 1)
debug(task)
task.name = "new_name"
new_db_sync.merge(task)
new_db_sync.commit()
debug(new_db_sync.identity_map)
assert new_db_sync.identity_map
new_db_sync.close()
debug(new_db_sync.identity_map)
assert not new_db_sync.identity_map

0 comments on commit 9b77a10

Please sign in to comment.