Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -70,15 +70,15 @@ class _ThreadedTestCase(unittest.TestCase): ...@@ -70,15 +70,15 @@ class _ThreadedTestCase(unittest.TestCase):
self.threads = [] self.threads = []
class TestPipeCondition(_ThreadedTestCase): class _ConditionTestCase(_ThreadedTestCase):
"""_PipeCondition tests""" """Common test case for conditions"""
def setUp(self): def setUp(self, cls):
_ThreadedTestCase.setUp(self) _ThreadedTestCase.setUp(self)
self.lock = threading.Lock() 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.assert_(not self.cond._is_owned())
self.assertRaises(RuntimeError, self.cond.wait) self.assertRaises(RuntimeError, self.cond.wait)
self.assertRaises(RuntimeError, self.cond.notifyAll) self.assertRaises(RuntimeError, self.cond.notifyAll)
...@@ -93,7 +93,7 @@ class TestPipeCondition(_ThreadedTestCase): ...@@ -93,7 +93,7 @@ class TestPipeCondition(_ThreadedTestCase):
self.assertRaises(RuntimeError, self.cond.wait) self.assertRaises(RuntimeError, self.cond.wait)
self.assertRaises(RuntimeError, self.cond.notifyAll) self.assertRaises(RuntimeError, self.cond.notifyAll)
def testNotification(self): def _testNotification(self):
def _NotifyAll(): def _NotifyAll():
self.cond.acquire() self.cond.acquire()
self.cond.notifyAll() self.cond.notifyAll()
...@@ -106,6 +106,19 @@ class TestPipeCondition(_ThreadedTestCase): ...@@ -106,6 +106,19 @@ class TestPipeCondition(_ThreadedTestCase):
self.cond.release() self.cond.release()
self.assert_(not self.cond._is_owned()) 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): def _TestWait(self, fn):
self._addThread(target=fn) self._addThread(target=fn)
self._addThread(target=fn) self._addThread(target=fn)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment