Revision 9c6c3d69 kamaki/clients/test.py
b/kamaki/clients/test.py | ||
---|---|---|
35 | 35 |
from time import sleep |
36 | 36 |
from inspect import getmembers, isclass |
37 | 37 |
from json import loads |
38 |
from random import randint |
|
38 | 39 |
|
39 | 40 |
from kamaki.clients.connection.test import ( |
40 | 41 |
KamakiConnection, |
... | ... | |
182 | 183 |
self.assertEqual(self.client.DATE_FORMATS, DATE_FORMATS) |
183 | 184 |
self.assertTrue(isinstance(self.client.http_client, FakeConnection)) |
184 | 185 |
|
186 |
def test__init_thread_limit(self): |
|
187 |
exp = 'Nothing set here' |
|
188 |
for faulty in (-1, 0.5, 'a string', {}): |
|
189 |
self.assertRaises( |
|
190 |
AssertionError, |
|
191 |
self.client._init_thread_limit, |
|
192 |
faulty) |
|
193 |
self.assertEqual(exp, getattr(self.client, '_thread_limit', exp)) |
|
194 |
self.assertEqual(exp, getattr(self.client, '_elapsed_old', exp)) |
|
195 |
self.assertEqual(exp, getattr(self.client, '_elapsed_new', exp)) |
|
196 |
self.client._init_thread_limit(42) |
|
197 |
self.assertEqual(42, self.client._thread_limit) |
|
198 |
self.assertEqual(0.0, self.client._elapsed_old) |
|
199 |
self.assertEqual(0.0, self.client._elapsed_new) |
|
200 |
|
|
201 |
def test__watch_thread_limit(self): |
|
202 |
waits = ( |
|
203 |
dict(args=((0.1, 1), (0.1, 2), (0.2, 1), (0.7, 1), (0.3, 2))), |
|
204 |
dict(args=((1.0 - (i / 10.0), (i + 1)) for i in range(7))), |
|
205 |
dict(max=1, args=tuple([(randint(1, 10) / 3.0, 1), ] * 10)), |
|
206 |
dict( |
|
207 |
limit=5, |
|
208 |
args=tuple([ |
|
209 |
(1.0 + (i / 10.0), (5 - i - 1)) for i in range(4)] + [ |
|
210 |
(2.0, 1), (1.9, 2), (2.0, 1), (2.0, 2)])), |
|
211 |
dict(args=tuple( |
|
212 |
[(1.0 - (i / 10.0), (i + 1)) for i in range(7)] + [ |
|
213 |
(0.1, 7), (0.2, 6), (0.4, 5), (0.3, 6), (0.2, 7), (0.1, 7)])),) |
|
214 |
for wait_dict in waits: |
|
215 |
if 'max' in wait_dict: |
|
216 |
self.client.MAX_THREADS = wait_dict['max'] |
|
217 |
else: |
|
218 |
self.client.MAX_THREADS = 7 |
|
219 |
if 'limit' in wait_dict: |
|
220 |
self.client._init_thread_limit(wait_dict['limit']) |
|
221 |
else: |
|
222 |
self.client._init_thread_limit() |
|
223 |
self.client._watch_thread_limit(list()) |
|
224 |
self.assertEqual(1, self.client._thread_limit) |
|
225 |
for wait, exp_limit in wait_dict['args']: |
|
226 |
self.client._elapsed_new = wait |
|
227 |
self.client._watch_thread_limit(list()) |
|
228 |
self.assertEqual(exp_limit, self.client._thread_limit) |
|
229 |
|
|
185 | 230 |
|
186 | 231 |
# TestCase auxiliary methods |
187 | 232 |
|
Also available in: Unified diff