Skip to content

Commit

Permalink
Add disclaimer for optimistic lock unexisting key
Browse files Browse the repository at this point in the history
  • Loading branch information
argaen committed Jun 21, 2017
1 parent a30dbfa commit e90dc50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions aiocache/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class OptimisticLock:
result = await super_expensive_call()
await cache.set('random_value') # This will make the `lock.cas` call fail
await lock.cas(result)
If the lock is created with an unexisting key, there will never be conflicts.
"""

def __init__(self, client: Type[BaseCache], key: str):
Expand Down
3 changes: 2 additions & 1 deletion tests/acceptance/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ async def test_release_does_nothing(self, lock):
assert await lock.__aexit__("exc_type", "exc_value", "traceback") is None

@pytest.mark.asyncio
async def test_check_and_set_not_existing(self, cache, lock):
async def test_check_and_set_not_existing_never_fails(self, cache, lock):
async with lock as locked:
await cache.set('conflicting_value')
await locked.cas('value')

assert await cache.get(pytest.KEY) == 'value'
Expand Down

0 comments on commit e90dc50

Please sign in to comment.