From c5fe2a67f9c4927948894e3ae87505de79013c70 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Thu, 1 Oct 2009 13:56:32 +0100 Subject: [PATCH] Abstract base condition test cases This way they can be used to test different condition classes. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- test/ganeti.locking_unittest.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test/ganeti.locking_unittest.py b/test/ganeti.locking_unittest.py index 3a77bc0f7..b279dddb1 100755 --- a/test/ganeti.locking_unittest.py +++ b/test/ganeti.locking_unittest.py @@ -70,15 +70,15 @@ class _ThreadedTestCase(unittest.TestCase): self.threads = [] -class TestPipeCondition(_ThreadedTestCase): - """_PipeCondition tests""" +class _ConditionTestCase(_ThreadedTestCase): + """Common test case for conditions""" - def setUp(self): + def setUp(self, cls): _ThreadedTestCase.setUp(self) self.lock = threading.Lock() - self.cond = locking._PipeCondition(self.lock) + self.cond = cls(self.lock) - def testAcquireRelease(self): + def _testAcquireRelease(self): self.assert_(not self.cond._is_owned()) self.assertRaises(RuntimeError, self.cond.wait) self.assertRaises(RuntimeError, self.cond.notifyAll) @@ -93,7 +93,7 @@ class TestPipeCondition(_ThreadedTestCase): self.assertRaises(RuntimeError, self.cond.wait) self.assertRaises(RuntimeError, self.cond.notifyAll) - def testNotification(self): + def _testNotification(self): def _NotifyAll(): self.cond.acquire() self.cond.notifyAll() @@ -106,6 +106,19 @@ class TestPipeCondition(_ThreadedTestCase): self.cond.release() self.assert_(not self.cond._is_owned()) + +class TestPipeCondition(_ConditionTestCase): + """_PipeCondition tests""" + + def setUp(self): + _ConditionTestCase.setUp(self, locking._PipeCondition) + + def testAcquireRelease(self): + self._testAcquireRelease() + + def testNotification(self): + self._testNotification() + def _TestWait(self, fn): self._addThread(target=fn) self._addThread(target=fn) -- GitLab