Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_queue.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | d8e9f6f57f13 |
| children | aef248c1645a aa0d2d51fbde |
| rev | line source |
|---|---|
|
23214
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
1 # Some simple Queue module tests, plus some failure conditions |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
2 # to ensure the Queue locks remain stable |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
3 import Queue |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
4 import sys |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
5 import threading |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
6 import time |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
7 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
8 from test_support import verify, TestFailed, verbose |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
9 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
10 queue_size = 5 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
11 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
12 # Execute a function that blocks, and in a seperate thread, a function that |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
13 # triggers the release. Returns the result of the blocking function. |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
14 class _TriggerThread(threading.Thread): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
15 def __init__(self, fn, args): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
16 self.fn = fn |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
17 self.args = args |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
18 self.startedEvent = threading.Event() |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
19 threading.Thread.__init__(self) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
20 def run(self): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
21 time.sleep(.1) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
22 self.startedEvent.set() |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
23 self.fn(*self.args) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
24 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
25 def _doBlockingTest( block_func, block_args, trigger_func, trigger_args): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
26 t = _TriggerThread(trigger_func, trigger_args) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
27 t.start() |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
28 try: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
29 return block_func(*block_args) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
30 finally: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
31 # If we unblocked before our thread made the call, we failed! |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
32 if not t.startedEvent.isSet(): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
33 raise TestFailed("blocking function '%r' appeared not to block" % (block_func,)) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
34 t.join(1) # make sure the thread terminates |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
35 if t.isAlive(): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
36 raise TestFailed("trigger function '%r' appeared to not return" % (trigger_func,)) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
37 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
38 # A Queue subclass that can provoke failure at a moment's notice :) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
39 class FailingQueueException(Exception): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
40 pass |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
41 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
42 class FailingQueue(Queue.Queue): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
43 def __init__(self, *args): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
44 self.fail_next_put = False |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
45 self.fail_next_get = False |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
46 Queue.Queue.__init__(self, *args) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
47 def _put(self, item): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
48 if self.fail_next_put: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
49 self.fail_next_put = False |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
50 raise FailingQueueException, "You Lose" |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
51 return Queue.Queue._put(self, item) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
52 def _get(self): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
53 if self.fail_next_get: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
54 self.fail_next_get = False |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
55 raise FailingQueueException, "You Lose" |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
56 return Queue.Queue._get(self) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
57 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
58 def FailingQueueTest(q): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
59 if not q.empty(): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
60 raise RuntimeError, "Call this function with an empty queue" |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
61 for i in range(queue_size-1): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
62 q.put(i) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
63 q.fail_next_put = True |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
64 # Test a failing non-blocking put. |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
65 try: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
66 q.put("oops", block=0) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
67 raise TestFailed("The queue didn't fail when it should have") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
68 except FailingQueueException: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
69 pass |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
70 q.put("last") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
71 verify(q.full(), "Queue should be full") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
72 q.fail_next_put = True |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
73 # Test a failing blocking put |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
74 try: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
75 _doBlockingTest( q.put, ("full",), q.get, ()) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
76 raise TestFailed("The queue didn't fail when it should have") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
77 except FailingQueueException: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
78 pass |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
79 # Check the Queue isn't damaged. |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
80 # put failed, but get succeeded - re-add |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
81 q.put("last") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
82 verify(q.full(), "Queue should be full") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
83 q.get() |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
84 verify(not q.full(), "Queue should not be full") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
85 q.put("last") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
86 verify(q.full(), "Queue should be full") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
87 # Test a blocking put |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
88 _doBlockingTest( q.put, ("full",), q.get, ()) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
89 # Empty it |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
90 for i in range(queue_size): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
91 q.get() |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
92 verify(q.empty(), "Queue should be empty") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
93 q.put("first") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
94 q.fail_next_get = True |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
95 try: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
96 q.get() |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
97 raise TestFailed("The queue didn't fail when it should have") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
98 except FailingQueueException: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
99 pass |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
100 verify(not q.empty(), "Queue should not be empty") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
101 q.get() |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
102 verify(q.empty(), "Queue should be empty") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
103 q.fail_next_get = True |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
104 try: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
105 _doBlockingTest( q.get, (), q.put, ('empty',)) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
106 raise TestFailed("The queue didn't fail when it should have") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
107 except FailingQueueException: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
108 pass |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
109 # put succeeded, but get failed. |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
110 verify(not q.empty(), "Queue should not be empty") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
111 q.get() |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
112 verify(q.empty(), "Queue should be empty") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
113 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
114 def SimpleQueueTest(q): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
115 if not q.empty(): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
116 raise RuntimeError, "Call this function with an empty queue" |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
117 # I guess we better check things actually queue correctly a little :) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
118 q.put(111) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
119 q.put(222) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
120 verify(q.get()==111 and q.get()==222, "Didn't seem to queue the correct data!") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
121 for i in range(queue_size-1): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
122 q.put(i) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
123 verify(not q.full(), "Queue should not be full") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
124 q.put("last") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
125 verify(q.full(), "Queue should be full") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
126 try: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
127 q.put("full", block=0) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
128 raise TestFailed("Didn't appear to block with a full queue") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
129 except Queue.Full: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
130 pass |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
131 # Test a blocking put |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
132 _doBlockingTest( q.put, ("full",), q.get, ()) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
133 # Empty it |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
134 for i in range(queue_size): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
135 q.get() |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
136 verify(q.empty(), "Queue should be empty") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
137 try: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
138 q.get(block=0) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
139 raise TestFailed("Didn't appear to block with an empty queue") |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
140 except Queue.Empty: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
141 pass |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
142 # Test a blocking get |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
143 _doBlockingTest( q.get, (), q.put, ('empty',)) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
144 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
145 def test(): |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
146 q=Queue.Queue(queue_size) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
147 # Do it a couple of times on the same queue |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
148 SimpleQueueTest(q) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
149 SimpleQueueTest(q) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
150 if verbose: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
151 print "Simple Queue tests seemed to work" |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
152 q = FailingQueue(queue_size) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
153 FailingQueueTest(q) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
154 FailingQueueTest(q) |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
155 if verbose: |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
156 print "Failing Queue tests seemed to work" |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
157 |
|
d8e9f6f57f13
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
158 test() |
