Commit c5fe2a67 authored by Guido Trotter's avatar Guido Trotter
Browse files

Abstract base condition test cases



This way they can be used to test different condition classes.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 63f2e724
......@@ -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)
......
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