Skip to content

Commit e13473e

Browse files
committed
Add unit test that demonstrates database lock when copy fails
1 parent ab2ee68 commit e13473e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_manager.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
import posixpath
44
import sys
5+
import sqlite3
6+
57
from unittest.mock import patch
68

79
import pytest
@@ -617,3 +619,29 @@ def test_db_journal_mode(any_fid_manager_class, fid_db_path, jp_root_dir, db_jou
617619
cursor = fid_manager.con.execute("PRAGMA journal_mode")
618620
actual_journal_mode = cursor.fetchone()
619621
assert actual_journal_mode[0].upper() == expected_journal_mode
622+
623+
624+
625+
def test_multiple_fileIdManager_connections_after_exception(fid_db_path):
626+
original_file_path = "/path/to/file"
627+
copy_location = "/path/to/copy"
628+
629+
manager_1 = ArbitraryFileIdManager(db_path=fid_db_path)
630+
631+
# Create an initial ID for this file
632+
manager_1.index(original_file_path)
633+
# Copy the file
634+
manager_1.copy(original_file_path, copy_location)
635+
# Try copying the file again.
636+
try:
637+
manager_1.copy(original_file_path, copy_location)
638+
# We expect this to fail because the file is already in the database.
639+
except sqlite3.IntegrityError:
640+
pass
641+
642+
# Now the database is locked and no other connections can be made.
643+
# Start a second connection to the database and demonstrate
644+
# that the database is not stuck in a locked state.
645+
manager_2 = ArbitraryFileIdManager(db_path=fid_db_path)
646+
manager_2.copy(original_file_path, copy_location)
647+

0 commit comments

Comments
 (0)