Skip to content

Commit

Permalink
Added test for MongoLock.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwaroquiers committed Jul 18, 2024
1 parent 281e710 commit e8a9534
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/db/utils/test_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from jobflow_remote.utils.db import MongoLock


class TestMongoLock:
def test_context(self, mongoclient):
db = mongoclient["mytestdb"]
collection = db["mytestcollection"]
collection.drop()
collection.insert_one({"a": 1})
collection.insert_one({"b": 2})
with MongoLock(collection=collection, filter={"a": 1}) as lock:
assert lock.locked_document is not None
lock_id = lock.lock_id
assert lock_id == lock.get_lock_id(lock.locked_document)
assert lock.is_locked is False
with MongoLock(collection=collection, filter={"a": 1}) as lock2:
assert lock2.locked_document is None
assert lock2.unavailable_document is None
assert lock2.is_locked is True
with MongoLock(
collection=collection, filter={"a": 1}, get_locked_doc=True
) as lock3:
assert lock3.locked_document is None
assert lock3.unavailable_document is not None
assert lock_id == lock3.get_lock_id(lock3.unavailable_document)
assert lock3.is_locked is True

0 comments on commit e8a9534

Please sign in to comment.