Skip to content

Commit c79a8ca

Browse files
committed
Test all table lock modes
1 parent 0bb392d commit c79a8ca

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

psqlextra/locking.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ class PostgresTableLockMode(Enum):
1919
EXCLUSIVE = "EXCLUSIVE"
2020
ACCESS_EXCLUSIVE = "ACCESS EXCLUSIVE"
2121

22+
@property
23+
def alias(self) -> str:
24+
return (
25+
"".join([word.title() for word in self.name.lower().split("_")])
26+
+ "Lock"
27+
)
28+
2229

2330
def postgres_lock_table(
2431
table_name: str,

tests/test_locking.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,17 @@ def test_postgres_lock_table_in_schema():
6666
assert lock_signature not in get_table_locks()
6767

6868

69+
@pytest.mark.parametrize("lock_mode", list(PostgresTableLockMode))
6970
@pytest.mark.django_db(transaction=True)
70-
def test_postgres_lock_mode(mocked_model):
71+
def test_postgres_lock_model(mocked_model, lock_mode):
7172
lock_signature = (
7273
"public",
7374
mocked_model._meta.db_table,
74-
"AccessExclusiveLock",
75+
lock_mode.alias,
7576
)
7677

7778
with transaction.atomic():
78-
postgres_lock_model(
79-
mocked_model, PostgresTableLockMode.ACCESS_EXCLUSIVE
80-
)
79+
postgres_lock_model(mocked_model, lock_mode)
8180
assert lock_signature in get_table_locks()
8281

8382
assert lock_signature not in get_table_locks()

0 commit comments

Comments
 (0)