locking: Add test for downgrade without names
authorMichael Hanselmann <hansmi@google.com>
Tue, 20 Nov 2012 03:19:12 +0000 (04:19 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 21 Nov 2012 01:44:08 +0000 (02:44 +0100)
Until now there was no test for calling “LockSet.downgrade” without
specifying any names.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

test/ganeti.locking_unittest.py

index 85fa0fc..494994c 100755 (executable)
@@ -1703,6 +1703,21 @@ class TestLockSet(_ThreadedTestCase):
 
     self.ls.release()
 
+  def testDowngradeEverything(self):
+    self.assertEqual(self.ls.acquire(locking.ALL_SET, shared=0),
+                     set(["one", "two", "three"]))
+
+    # Ensure all locks are now owned in exclusive mode
+    for name in self.ls._names():
+      self.assertTrue(self.ls.check_owned(name, shared=0))
+
+    # Downgrade everything
+    self.assertTrue(self.ls.downgrade())
+
+    # Ensure all locks are now owned in shared mode
+    for name in self.ls._names():
+      self.assertTrue(self.ls.check_owned(name, shared=1))
+
   def testPriority(self):
     def _Acquire(prev, next, name, priority, success_fn):
       prev.wait()