Revision 34cb5617 test/ganeti.locking_unittest.py
b/test/ganeti.locking_unittest.py | ||
---|---|---|
114 | 114 |
self.assert_(not self.cond._is_owned()) |
115 | 115 |
|
116 | 116 |
|
117 |
class TestSingleNotifyPipeCondition(_ConditionTestCase): |
|
118 |
"""SingleNotifyPipeCondition tests""" |
|
119 |
|
|
120 |
def setUp(self): |
|
121 |
_ConditionTestCase.setUp(self, locking.SingleNotifyPipeCondition) |
|
122 |
|
|
123 |
def testAcquireRelease(self): |
|
124 |
self._testAcquireRelease() |
|
125 |
|
|
126 |
def testNotification(self): |
|
127 |
self._testNotification() |
|
128 |
|
|
129 |
def testWaitReuse(self): |
|
130 |
self.cond.acquire() |
|
131 |
self.cond.wait(0) |
|
132 |
self.cond.wait(0.1) |
|
133 |
self.cond.release() |
|
134 |
|
|
135 |
def testNoNotifyReuse(self): |
|
136 |
self.cond.acquire() |
|
137 |
self.cond.notifyAll() |
|
138 |
self.assertRaises(RuntimeError, self.cond.wait) |
|
139 |
self.assertRaises(RuntimeError, self.cond.notifyAll) |
|
140 |
self.cond.release() |
|
141 |
|
|
142 |
|
|
117 | 143 |
class TestPipeCondition(_ConditionTestCase): |
118 |
"""_PipeCondition tests"""
|
|
144 |
"""PipeCondition tests""" |
|
119 | 145 |
|
120 | 146 |
def setUp(self): |
121 |
_ConditionTestCase.setUp(self, locking._PipeCondition)
|
|
147 |
_ConditionTestCase.setUp(self, locking.PipeCondition) |
|
122 | 148 |
|
123 | 149 |
def testAcquireRelease(self): |
124 | 150 |
self._testAcquireRelease() |
... | ... | |
214 | 240 |
self.assertRaises(Queue.Empty, self.done.get_nowait) |
215 | 241 |
|
216 | 242 |
|
217 |
class TestSingleActionPipeCondition(unittest.TestCase): |
|
218 |
"""_SingleActionPipeCondition tests""" |
|
219 |
|
|
220 |
def setUp(self): |
|
221 |
self.cond = locking._SingleActionPipeCondition() |
|
222 |
|
|
223 |
def testInitialization(self): |
|
224 |
self.assert_(self.cond._read_fd is not None) |
|
225 |
self.assert_(self.cond._write_fd is not None) |
|
226 |
self.assert_(self.cond._poller is not None) |
|
227 |
self.assertEqual(self.cond._nwaiters, 0) |
|
228 |
|
|
229 |
def testUsageCount(self): |
|
230 |
self.cond.StartWaiting() |
|
231 |
self.assert_(self.cond._read_fd is not None) |
|
232 |
self.assert_(self.cond._write_fd is not None) |
|
233 |
self.assert_(self.cond._poller is not None) |
|
234 |
self.assertEqual(self.cond._nwaiters, 1) |
|
235 |
|
|
236 |
# use again |
|
237 |
self.cond.StartWaiting() |
|
238 |
self.assertEqual(self.cond._nwaiters, 2) |
|
239 |
|
|
240 |
# there is more than one user |
|
241 |
self.assert_(not self.cond.DoneWaiting()) |
|
242 |
self.assert_(self.cond._read_fd is not None) |
|
243 |
self.assert_(self.cond._write_fd is not None) |
|
244 |
self.assert_(self.cond._poller is not None) |
|
245 |
self.assertEqual(self.cond._nwaiters, 1) |
|
246 |
|
|
247 |
self.assert_(self.cond.DoneWaiting()) |
|
248 |
self.assertEqual(self.cond._nwaiters, 0) |
|
249 |
self.assert_(self.cond._read_fd is None) |
|
250 |
self.assert_(self.cond._write_fd is None) |
|
251 |
self.assert_(self.cond._poller is None) |
|
252 |
|
|
253 |
def testNotify(self): |
|
254 |
wait1 = self.cond.StartWaiting() |
|
255 |
wait2 = self.cond.StartWaiting() |
|
256 |
|
|
257 |
self.assert_(self.cond._read_fd is not None) |
|
258 |
self.assert_(self.cond._write_fd is not None) |
|
259 |
self.assert_(self.cond._poller is not None) |
|
260 |
|
|
261 |
self.cond.notifyAll() |
|
262 |
|
|
263 |
self.assert_(self.cond._read_fd is not None) |
|
264 |
self.assert_(self.cond._write_fd is None) |
|
265 |
self.assert_(self.cond._poller is not None) |
|
266 |
|
|
267 |
self.assert_(not self.cond.DoneWaiting()) |
|
268 |
|
|
269 |
self.assert_(self.cond._read_fd is not None) |
|
270 |
self.assert_(self.cond._write_fd is None) |
|
271 |
self.assert_(self.cond._poller is not None) |
|
272 |
|
|
273 |
self.assert_(self.cond.DoneWaiting()) |
|
274 |
|
|
275 |
self.assert_(self.cond._read_fd is None) |
|
276 |
self.assert_(self.cond._write_fd is None) |
|
277 |
self.assert_(self.cond._poller is None) |
|
278 |
|
|
279 |
def testReusage(self): |
|
280 |
self.cond.StartWaiting() |
|
281 |
self.assert_(self.cond._read_fd is not None) |
|
282 |
self.assert_(self.cond._write_fd is not None) |
|
283 |
self.assert_(self.cond._poller is not None) |
|
284 |
|
|
285 |
self.assert_(self.cond.DoneWaiting()) |
|
286 |
|
|
287 |
self.assertRaises(RuntimeError, self.cond.StartWaiting) |
|
288 |
self.assert_(self.cond._read_fd is None) |
|
289 |
self.assert_(self.cond._write_fd is None) |
|
290 |
self.assert_(self.cond._poller is None) |
|
291 |
|
|
292 |
def testNotifyTwice(self): |
|
293 |
self.cond.notifyAll() |
|
294 |
self.assertRaises(RuntimeError, self.cond.notifyAll) |
|
295 |
|
|
296 |
|
|
297 | 243 |
class TestSharedLock(_ThreadedTestCase): |
298 | 244 |
"""SharedLock tests""" |
299 | 245 |
|
Also available in: Unified diff