Commit a66bd91b authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

locking.SharedLock: Fix bug in delete function



SharedLock.__acquire_unlocked uses keyword parameters. Just passing
the timeout would set the “shared” parameter.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 5e0a6daf
......@@ -520,7 +520,7 @@ class SharedLock(object):
"""
return self.__pending[0] == cond
def __acquire_unlocked(self, shared=0, timeout=None):
def __acquire_unlocked(self, shared, timeout):
"""Acquire a shared lock.
@param shared: whether to acquire in shared mode; by default an
......@@ -641,7 +641,10 @@ class SharedLock(object):
acquired = self.__is_exclusive()
if not acquired:
acquired = self.__acquire_unlocked(timeout)
acquired = self.__acquire_unlocked(0, timeout)
assert self.__is_exclusive() and not self.__is_sharer(), \
"Lock wasn't acquired in exclusive mode"
if acquired:
self.__deleted = True
......
......@@ -447,6 +447,9 @@ class TestSharedLock(_ThreadedTestCase):
self.assertRaises(errors.LockError, self.sl.acquire, shared=1)
self.assertRaises(errors.LockError, self.sl.delete)
def testDeleteTimeout(self):
self.sl.delete(timeout=60)
def testNoDeleteIfSharer(self):
self.sl.acquire(shared=1)
self.assertRaises(AssertionError, self.sl.delete)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment