-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
281e710
commit e8a9534
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |