Skip to content

Commit

Permalink
Fill in rest of coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Dec 2, 2024
1 parent ae40228 commit a20bf81
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test_app/tests/lib/utils/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
from django.db import connection
from django.db.utils import OperationalError

from ansible_base.lib.utils.db import advisory_lock, migrations_are_complete

Expand Down Expand Up @@ -40,3 +41,25 @@ def test_determine_lock_is_held(django_db_blocker):
else:
raise RuntimeError('Other thread never obtained lock')
thread.join()


@pytest.mark.django_db
def test_tuple_lock():
with advisory_lock([1234, 4321]):
pass


@pytest.mark.django_db
def test_invalid_tuple_name():
with pytest.raises(ValueError):
with advisory_lock(['test_invalid_tuple_name', 'foo']):
pass


@pytest.mark.django_db
def test_lock_session_timeout_milliseconds():
with pytest.raises(OperationalError) as exc:
# uses miliseconds units
with advisory_lock('test_lock_session_timeout_milliseconds', lock_session_timeout_milliseconds=2):
time.sleep(3)
assert 'the connection is lost' in str(exc)

0 comments on commit a20bf81

Please sign in to comment.