Commit 3f404fc5 authored by Guido Trotter's avatar Guido Trotter
Browse files

LockSet: improve remove() api

Lockset's remove() function used to return a list of locks we failed to remove.
Rather than doing this we'll return a list of removed locks, so it's more
similar to how acquire() behaves. This patch also fixes the relevant unit tests.

Reviewed-by: imsnah
parent 0cc00929
......@@ -512,8 +512,8 @@ class LockSet:
you are already holding exclusively the locks.
A list of lock which we failed to delete. The list is always empty if we
were holding all the locks exclusively.
A list of lock which we removed. The list is always equal to the names
list if we were holding all the locks exclusively.
if not blocking and not self._is_owned():
......@@ -530,7 +530,7 @@ class LockSet:
assert not self._is_owned() or self._list_owned().issuperset(names), (
"remove() on acquired lockset while not owning all elements")
removed = []
for lname in names:
# Calling delete() acquires the lock exclusively if we don't already own
......@@ -540,8 +540,8 @@ class LockSet:
# everything we want to delete, or we hold none.
except (KeyError, errors.LockError):
# This cannot happen if we were already holding it, verify:
assert not self._is_owned(), "remove failed while holding lockset"
......@@ -557,7 +557,7 @@ class LockSet:
if self._is_owned():
return delete_failed
return removed
# Locking levels, must be acquired in increasing order.
......@@ -291,7 +291,7 @@ class TestLockSet(unittest.TestCase):
self.assert_('six' in
self.assert_('seven' in
self.assertEquals(, set(['five', 'six', 'seven']))['five', 'six'])
self.assertEquals(['five', 'six']), ['five', 'six'])
self.assert_('five' not in
self.assert_('six' not in
self.assertEquals(, set(['seven']))
......@@ -305,18 +305,19 @@ class TestLockSet(unittest.TestCase):['two'])
self.assert_('two' not in'three')['three'])
self.assertEquals(['three']), ['three'])
self.assert_('three' not in
self.assertEquals('three'), ['three'])
self.assertEquals(['one', 'three', 'six']), ['three', 'six'])
self.assertEquals('three'), [])
self.assertEquals(['one', 'three', 'six']), ['one'])
self.assert_('one' not in
def testRemoveNonBlocking(self):
self.assertRaises(NotImplementedError,, 'one', blocking=0)'one')
self.assertEquals('one', blocking=0), [])
self.assertEquals('one', blocking=0), ['one'])['two', 'three'])
self.assertEquals(['two', 'three'], blocking=0), [])
self.assertEquals(['two', 'three'], blocking=0),
['two', 'three'])
def testNoDoubleAdd(self):
self.assertRaises(errors.LockError,, 'two')
......@@ -406,9 +407,9 @@ class TestLockSet(unittest.TestCase):
Thread(target=self._doRemoveSet, args=(['four', 'six'], )).start()
self.assertRaises(Queue.Empty, self.done.get, True, 0.2)'four')
self.assertEqual(self.done.get(True, 1), ['four'])
self.assertEqual(self.done.get(True, 1), ['six'])
Thread(target=self._doRemoveSet, args=(['two'])).start()
self.assertEqual(self.done.get(True, 1), [])
self.assertEqual(self.done.get(True, 1), ['two'])
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