Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 1 | # Some simple queue module tests, plus some failure conditions |
Tim Peters | afe5297 | 2004-08-20 02:37:25 +0000 | [diff] [blame] | 2 | # to ensure the Queue locks remain stable. |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 3 | import queue |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 4 | import time |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 5 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 6 | from test import support |
Victor Stinner | 45df820 | 2010-04-28 22:31:17 +0000 | [diff] [blame] | 7 | threading = support.import_module('threading') |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 8 | |
Tim Peters | afe5297 | 2004-08-20 02:37:25 +0000 | [diff] [blame] | 9 | QUEUE_SIZE = 5 |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 10 | |
Raymond Hettinger | da3caed | 2008-01-14 21:39:24 +0000 | [diff] [blame] | 11 | def qfull(q): |
| 12 | return q.maxsize > 0 and q.qsize() == q.maxsize |
| 13 | |
Tim Peters | afe5297 | 2004-08-20 02:37:25 +0000 | [diff] [blame] | 14 | # A thread to run a function that unclogs a blocked Queue. |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 15 | class _TriggerThread(threading.Thread): |
| 16 | def __init__(self, fn, args): |
| 17 | self.fn = fn |
| 18 | self.args = args |
| 19 | self.startedEvent = threading.Event() |
| 20 | threading.Thread.__init__(self) |
Tim Peters | afe5297 | 2004-08-20 02:37:25 +0000 | [diff] [blame] | 21 | |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 22 | def run(self): |
Tim Peters | 8d7626c | 2004-08-20 03:27:12 +0000 | [diff] [blame] | 23 | # The sleep isn't necessary, but is intended to give the blocking |
| 24 | # function in the main thread a chance at actually blocking before |
| 25 | # we unclog it. But if the sleep is longer than the timeout-based |
| 26 | # tests wait in their blocking functions, those tests will fail. |
| 27 | # So we give them much longer timeout values compared to the |
| 28 | # sleep here (I aimed at 10 seconds for blocking functions -- |
| 29 | # they should never actually wait that long - they should make |
| 30 | # progress as soon as we call self.fn()). |
| 31 | time.sleep(0.1) |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 32 | self.startedEvent.set() |
| 33 | self.fn(*self.args) |
| 34 | |
Tim Peters | 8d7626c | 2004-08-20 03:27:12 +0000 | [diff] [blame] | 35 | |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 36 | # Execute a function that blocks, and in a separate thread, a function that |
| 37 | # triggers the release. Returns the result of the blocking function. Caution: |
| 38 | # block_func must guarantee to block until trigger_func is called, and |
| 39 | # trigger_func must guarantee to change queue state so that block_func can make |
| 40 | # enough progress to return. In particular, a block_func that just raises an |
| 41 | # exception regardless of whether trigger_func is called will lead to |
| 42 | # timing-dependent sporadic failures, and one of those went rarely seen but |
| 43 | # undiagnosed for years. Now block_func must be unexceptional. If block_func |
| 44 | # is supposed to raise an exception, call do_exceptional_blocking_test() |
| 45 | # instead. |
| 46 | |
| 47 | class BlockingTestMixin: |
| 48 | |
| 49 | def do_blocking_test(self, block_func, block_args, trigger_func, trigger_args): |
| 50 | self.t = _TriggerThread(trigger_func, trigger_args) |
| 51 | self.t.start() |
| 52 | self.result = block_func(*block_args) |
| 53 | # If block_func returned before our thread made the call, we failed! |
Benjamin Peterson | 672b803 | 2008-06-11 19:14:14 +0000 | [diff] [blame] | 54 | if not self.t.startedEvent.is_set(): |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 55 | self.fail("blocking function '%r' appeared not to block" % |
| 56 | block_func) |
| 57 | self.t.join(10) # make sure the thread terminates |
Benjamin Peterson | 672b803 | 2008-06-11 19:14:14 +0000 | [diff] [blame] | 58 | if self.t.is_alive(): |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 59 | self.fail("trigger function '%r' appeared to not return" % |
| 60 | trigger_func) |
| 61 | return self.result |
| 62 | |
| 63 | # Call this instead if block_func is supposed to raise an exception. |
| 64 | def do_exceptional_blocking_test(self,block_func, block_args, trigger_func, |
| 65 | trigger_args, expected_exception_class): |
| 66 | self.t = _TriggerThread(trigger_func, trigger_args) |
| 67 | self.t.start() |
Tim Peters | 8d7626c | 2004-08-20 03:27:12 +0000 | [diff] [blame] | 68 | try: |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 69 | try: |
| 70 | block_func(*block_args) |
| 71 | except expected_exception_class: |
| 72 | raise |
| 73 | else: |
| 74 | self.fail("expected exception of kind %r" % |
| 75 | expected_exception_class) |
| 76 | finally: |
| 77 | self.t.join(10) # make sure the thread terminates |
Benjamin Peterson | 672b803 | 2008-06-11 19:14:14 +0000 | [diff] [blame] | 78 | if self.t.is_alive(): |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 79 | self.fail("trigger function '%r' appeared to not return" % |
| 80 | trigger_func) |
Benjamin Peterson | 672b803 | 2008-06-11 19:14:14 +0000 | [diff] [blame] | 81 | if not self.t.startedEvent.is_set(): |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 82 | self.fail("trigger thread ended but event never set") |
| 83 | |
| 84 | |
| 85 | class BaseQueueTest(unittest.TestCase, BlockingTestMixin): |
| 86 | def setUp(self): |
| 87 | self.cum = 0 |
| 88 | self.cumlock = threading.Lock() |
| 89 | |
| 90 | def simple_queue_test(self, q): |
| 91 | if q.qsize(): |
| 92 | raise RuntimeError("Call this function with an empty queue") |
Brett Cannon | 671153d | 2010-07-23 16:56:21 +0000 | [diff] [blame] | 93 | self.assertTrue(q.empty()) |
| 94 | self.assertFalse(q.full()) |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 95 | # I guess we better check things actually queue correctly a little :) |
| 96 | q.put(111) |
| 97 | q.put(333) |
| 98 | q.put(222) |
| 99 | target_order = dict(Queue = [111, 333, 222], |
| 100 | LifoQueue = [222, 333, 111], |
| 101 | PriorityQueue = [111, 222, 333]) |
| 102 | actual_order = [q.get(), q.get(), q.get()] |
| 103 | self.assertEquals(actual_order, target_order[q.__class__.__name__], |
| 104 | "Didn't seem to queue the correct data!") |
| 105 | for i in range(QUEUE_SIZE-1): |
| 106 | q.put(i) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 107 | self.assertTrue(q.qsize(), "Queue should not be empty") |
| 108 | self.assertTrue(not qfull(q), "Queue should not be full") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 109 | last = 2 * QUEUE_SIZE |
| 110 | full = 3 * 2 * QUEUE_SIZE |
| 111 | q.put(last) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 112 | self.assertTrue(qfull(q), "Queue should be full") |
Brett Cannon | 671153d | 2010-07-23 16:56:21 +0000 | [diff] [blame] | 113 | self.assertFalse(q.empty()) |
| 114 | self.assertTrue(q.full()) |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 115 | try: |
| 116 | q.put(full, block=0) |
| 117 | self.fail("Didn't appear to block with a full queue") |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 118 | except queue.Full: |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 119 | pass |
| 120 | try: |
| 121 | q.put(full, timeout=0.01) |
| 122 | self.fail("Didn't appear to time-out with a full queue") |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 123 | except queue.Full: |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 124 | pass |
| 125 | # Test a blocking put |
| 126 | self.do_blocking_test(q.put, (full,), q.get, ()) |
| 127 | self.do_blocking_test(q.put, (full, True, 10), q.get, ()) |
| 128 | # Empty it |
| 129 | for i in range(QUEUE_SIZE): |
| 130 | q.get() |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 131 | self.assertTrue(not q.qsize(), "Queue should be empty") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 132 | try: |
| 133 | q.get(block=0) |
| 134 | self.fail("Didn't appear to block with an empty queue") |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 135 | except queue.Empty: |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 136 | pass |
| 137 | try: |
| 138 | q.get(timeout=0.01) |
| 139 | self.fail("Didn't appear to time-out with an empty queue") |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 140 | except queue.Empty: |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 141 | pass |
| 142 | # Test a blocking get |
| 143 | self.do_blocking_test(q.get, (), q.put, ('empty',)) |
| 144 | self.do_blocking_test(q.get, (True, 10), q.put, ('empty',)) |
| 145 | |
| 146 | |
| 147 | def worker(self, q): |
| 148 | while True: |
| 149 | x = q.get() |
Amaury Forgeot d'Arc | b4febc7 | 2008-04-01 21:23:34 +0000 | [diff] [blame] | 150 | if x < 0: |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 151 | q.task_done() |
| 152 | return |
| 153 | with self.cumlock: |
| 154 | self.cum += x |
| 155 | q.task_done() |
| 156 | |
| 157 | def queue_join_test(self, q): |
| 158 | self.cum = 0 |
| 159 | for i in (0,1): |
| 160 | threading.Thread(target=self.worker, args=(q,)).start() |
| 161 | for i in range(100): |
| 162 | q.put(i) |
| 163 | q.join() |
| 164 | self.assertEquals(self.cum, sum(range(100)), |
| 165 | "q.join() did not block until all tasks were done") |
Amaury Forgeot d'Arc | b4febc7 | 2008-04-01 21:23:34 +0000 | [diff] [blame] | 166 | for i in (0,1): |
| 167 | q.put(-1) # instruct the threads to close |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 168 | q.join() # verify that you can join twice |
| 169 | |
| 170 | def test_queue_task_done(self): |
| 171 | # Test to make sure a queue task completed successfully. |
| 172 | q = self.type2test() |
| 173 | try: |
| 174 | q.task_done() |
| 175 | except ValueError: |
| 176 | pass |
Tim Peters | 8d7626c | 2004-08-20 03:27:12 +0000 | [diff] [blame] | 177 | else: |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 178 | self.fail("Did not detect task count going negative") |
| 179 | |
| 180 | def test_queue_join(self): |
| 181 | # Test that a queue join()s successfully, and before anything else |
| 182 | # (done twice for insurance). |
| 183 | q = self.type2test() |
| 184 | self.queue_join_test(q) |
| 185 | self.queue_join_test(q) |
| 186 | try: |
| 187 | q.task_done() |
| 188 | except ValueError: |
| 189 | pass |
| 190 | else: |
| 191 | self.fail("Did not detect task count going negative") |
| 192 | |
| 193 | def test_simple_queue(self): |
| 194 | # Do it a couple of times on the same queue. |
| 195 | # Done twice to make sure works with same instance reused. |
| 196 | q = self.type2test(QUEUE_SIZE) |
| 197 | self.simple_queue_test(q) |
| 198 | self.simple_queue_test(q) |
| 199 | |
Brett Cannon | 671153d | 2010-07-23 16:56:21 +0000 | [diff] [blame] | 200 | def test_negative_timeout_raises_exception(self): |
| 201 | q = self.type2test(QUEUE_SIZE) |
| 202 | with self.assertRaises(ValueError): |
| 203 | q.put(1, timeout=-1) |
| 204 | with self.assertRaises(ValueError): |
| 205 | q.get(1, timeout=-1) |
| 206 | |
| 207 | def test_nowait(self): |
| 208 | q = self.type2test(QUEUE_SIZE) |
| 209 | for i in range(QUEUE_SIZE): |
| 210 | q.put_nowait(1) |
| 211 | with self.assertRaises(queue.Full): |
| 212 | q.put_nowait(1) |
| 213 | |
| 214 | for i in range(QUEUE_SIZE): |
| 215 | q.get_nowait() |
| 216 | with self.assertRaises(queue.Empty): |
| 217 | q.get_nowait() |
| 218 | |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 219 | |
| 220 | class QueueTest(BaseQueueTest): |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 221 | type2test = queue.Queue |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 222 | |
| 223 | class LifoQueueTest(BaseQueueTest): |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 224 | type2test = queue.LifoQueue |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 225 | |
| 226 | class PriorityQueueTest(BaseQueueTest): |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 227 | type2test = queue.PriorityQueue |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 228 | |
| 229 | |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 230 | |
| 231 | # A Queue subclass that can provoke failure at a moment's notice :) |
| 232 | class FailingQueueException(Exception): |
| 233 | pass |
| 234 | |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 235 | class FailingQueue(queue.Queue): |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 236 | def __init__(self, *args): |
| 237 | self.fail_next_put = False |
| 238 | self.fail_next_get = False |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 239 | queue.Queue.__init__(self, *args) |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 240 | def _put(self, item): |
| 241 | if self.fail_next_put: |
| 242 | self.fail_next_put = False |
Collin Winter | 3add4d7 | 2007-08-29 23:37:32 +0000 | [diff] [blame] | 243 | raise FailingQueueException("You Lose") |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 244 | return queue.Queue._put(self, item) |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 245 | def _get(self): |
| 246 | if self.fail_next_get: |
| 247 | self.fail_next_get = False |
Collin Winter | 3add4d7 | 2007-08-29 23:37:32 +0000 | [diff] [blame] | 248 | raise FailingQueueException("You Lose") |
Alexandre Vassalotti | f260e44 | 2008-05-11 19:59:59 +0000 | [diff] [blame] | 249 | return queue.Queue._get(self) |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 250 | |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 251 | class FailingQueueTest(unittest.TestCase, BlockingTestMixin): |
Mark Hammond | 3b959db | 2002-04-19 00:11:32 +0000 | [diff] [blame] | 252 | |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 253 | def failing_queue_test(self, q): |
| 254 | if q.qsize(): |
| 255 | raise RuntimeError("Call this function with an empty queue") |
| 256 | for i in range(QUEUE_SIZE-1): |
| 257 | q.put(i) |
| 258 | # Test a failing non-blocking put. |
| 259 | q.fail_next_put = True |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 260 | try: |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 261 | q.put("oops", block=0) |
| 262 | self.fail("The queue didn't fail when it should have") |
| 263 | except FailingQueueException: |
| 264 | pass |
| 265 | q.fail_next_put = True |
| 266 | try: |
| 267 | q.put("oops", timeout=0.1) |
| 268 | self.fail("The queue didn't fail when it should have") |
| 269 | except FailingQueueException: |
| 270 | pass |
| 271 | q.put("last") |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 272 | self.assertTrue(qfull(q), "Queue should be full") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 273 | # Test a failing blocking put |
| 274 | q.fail_next_put = True |
| 275 | try: |
| 276 | self.do_blocking_test(q.put, ("full",), q.get, ()) |
| 277 | self.fail("The queue didn't fail when it should have") |
| 278 | except FailingQueueException: |
| 279 | pass |
| 280 | # Check the Queue isn't damaged. |
| 281 | # put failed, but get succeeded - re-add |
| 282 | q.put("last") |
| 283 | # Test a failing timeout put |
| 284 | q.fail_next_put = True |
| 285 | try: |
| 286 | self.do_exceptional_blocking_test(q.put, ("full", True, 10), q.get, (), |
| 287 | FailingQueueException) |
| 288 | self.fail("The queue didn't fail when it should have") |
| 289 | except FailingQueueException: |
| 290 | pass |
| 291 | # Check the Queue isn't damaged. |
| 292 | # put failed, but get succeeded - re-add |
| 293 | q.put("last") |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 294 | self.assertTrue(qfull(q), "Queue should be full") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 295 | q.get() |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 296 | self.assertTrue(not qfull(q), "Queue should not be full") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 297 | q.put("last") |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 298 | self.assertTrue(qfull(q), "Queue should be full") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 299 | # Test a blocking put |
| 300 | self.do_blocking_test(q.put, ("full",), q.get, ()) |
| 301 | # Empty it |
| 302 | for i in range(QUEUE_SIZE): |
| 303 | q.get() |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 304 | self.assertTrue(not q.qsize(), "Queue should be empty") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 305 | q.put("first") |
| 306 | q.fail_next_get = True |
| 307 | try: |
| 308 | q.get() |
| 309 | self.fail("The queue didn't fail when it should have") |
| 310 | except FailingQueueException: |
| 311 | pass |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 312 | self.assertTrue(q.qsize(), "Queue should not be empty") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 313 | q.fail_next_get = True |
| 314 | try: |
| 315 | q.get(timeout=0.1) |
| 316 | self.fail("The queue didn't fail when it should have") |
| 317 | except FailingQueueException: |
| 318 | pass |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 319 | self.assertTrue(q.qsize(), "Queue should not be empty") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 320 | q.get() |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 321 | self.assertTrue(not q.qsize(), "Queue should be empty") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 322 | q.fail_next_get = True |
| 323 | try: |
| 324 | self.do_exceptional_blocking_test(q.get, (), q.put, ('empty',), |
| 325 | FailingQueueException) |
| 326 | self.fail("The queue didn't fail when it should have") |
| 327 | except FailingQueueException: |
| 328 | pass |
| 329 | # put succeeded, but get failed. |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 330 | self.assertTrue(q.qsize(), "Queue should not be empty") |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 331 | q.get() |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 332 | self.assertTrue(not q.qsize(), "Queue should be empty") |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 333 | |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 334 | def test_failing_queue(self): |
| 335 | # Test to make sure a queue is functioning correctly. |
| 336 | # Done twice to the same instance. |
| 337 | q = FailingQueue(QUEUE_SIZE) |
| 338 | self.failing_queue_test(q) |
| 339 | self.failing_queue_test(q) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 340 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 341 | |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 342 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 343 | support.run_unittest(QueueTest, LifoQueueTest, PriorityQueueTest, |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 344 | FailingQueueTest) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 345 | |
Christian Heimes | 679db4a | 2008-01-18 09:56:22 +0000 | [diff] [blame] | 346 | |
Georg Brandl | 0e3b0ec | 2008-02-05 18:48:51 +0000 | [diff] [blame] | 347 | if __name__ == "__main__": |
| 348 | test_main() |