From 2e1d6d96bf251a48d60966eaa9cfedb00ee393d6 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Tue, 8 Jul 2008 16:31:24 +0000
Subject: [PATCH] Add a new LockSet unittest

This test checks the LockSet behaviour when an empty list is passed.
The current behaviour is expected, but since this is a corner case,
we're safer to keep it under a check, and if we need a different one
monitor that everything is as we expect it to be.

Reviewed-by: imsnah
---
 test/ganeti.locking_unittest.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/test/ganeti.locking_unittest.py b/test/ganeti.locking_unittest.py
index ee94e12a5..e2558e7b2 100755
--- a/test/ganeti.locking_unittest.py
+++ b/test/ganeti.locking_unittest.py
@@ -403,6 +403,18 @@ class TestLockSet(unittest.TestCase):
     self.assertRaises(AssertionError, self.ls.add, 'five')
     self.ls.release()
 
+  def testEmptyAcquire(self):
+    # Acquire an empty list of locks...
+    self.assertEquals(self.ls.acquire([]), set())
+    self.assertEquals(self.ls._list_owned(), set())
+    # New locks can still be addded
+    self.assert_(self.ls.add('six'))
+    # "re-acquiring" is not an issue, since we had really acquired nothing
+    self.assertEquals(self.ls.acquire([], shared=1), set())
+    self.assertEquals(self.ls._list_owned(), set())
+    # We haven't really acquired anything, so we cannot release
+    self.assertRaises(AssertionError, self.ls.release)
+
   def _doLockSet(self, set, shared):
     try:
       self.ls.acquire(set, shared=shared)
-- 
GitLab