Revision db113224 kamaki/clients/test/__init__.py
b/kamaki/clients/test/__init__.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from unittest import makeSuite, TestSuite, TextTestRunner |
|
34 |
from unittest import makeSuite, TestSuite, TextTestRunner, TestCase |
|
35 |
from time import sleep |
|
35 | 36 |
|
36 | 37 |
from kamaki.clients.test.astakos import Astakos |
37 | 38 |
#from kamaki.clients.test.cyclades import Cyclades |
... | ... | |
54 | 55 |
yield (obj, objname) |
55 | 56 |
|
56 | 57 |
|
58 |
class SilentEvent(TestCase): |
|
59 |
|
|
60 |
can_finish = -1 |
|
61 |
|
|
62 |
def thread_content(self, methodid): |
|
63 |
wait = 0.1 |
|
64 |
while self.can_finish < methodid and wait < 4: |
|
65 |
sleep(wait) |
|
66 |
wait = 2 * wait |
|
67 |
self.assertTrue(wait < 4) |
|
68 |
|
|
69 |
def setUp(self): |
|
70 |
from kamaki.clients import SilentEvent |
|
71 |
self.SE = SilentEvent |
|
72 |
|
|
73 |
def test_parallel(self): |
|
74 |
threads = [] |
|
75 |
for i in range(4): |
|
76 |
threads.append(self.SE(self.thread_content, i)) |
|
77 |
|
|
78 |
for t in threads: |
|
79 |
t.start() |
|
80 |
|
|
81 |
for i in range(4): |
|
82 |
self.assertTrue(threads[i].is_alive()) |
|
83 |
self.can_finish = i |
|
84 |
threads[i].join() |
|
85 |
self.assertFalse(threads[i].is_alive()) |
|
86 |
|
|
87 |
|
|
57 | 88 |
def main(argv): |
58 | 89 |
found = False |
59 | 90 |
for cls, name in get_test_classes(name=argv[1] if len(argv) > 1 else ''): |
Also available in: Unified diff