move limits logic entirely into STATUS

This commit is contained in:
Alexey Lavrenuke (load testing) 2013-07-16 16:18:46 +04:00
parent 67562b3e46
commit d51781de66
3 changed files with 18 additions and 24 deletions

View File

@ -25,14 +25,16 @@ class ComponentFactory():
self.http_ver = http_ver
self.ammo_file = ammo_file
self.instances_schedule = instances_schedule
self.loop_limit = int(loop_limit)
if self.loop_limit == -1: # -1 means infinite
self.loop_limit = 0
self.ammo_limit = int(ammo_limit)
if self.ammo_limit == -1: # -1 means infinite
self.ammo_limit = 0
if self.loop_limit is 0 and self.ammo_limit is 0:
self.loop_limit = 1 # we should have only one loop if we have instance_schedule
loop_limit = int(loop_limit)
if loop_limit == -1: # -1 means infinite
loop_limit = 0
ammo_limit = int(ammo_limit)
if ammo_limit == -1: # -1 means infinite
ammo_limit = 0
if loop_limit is 0 and ammo_limit is 0:
loop_limit = 1 # we should have only one loop if we have instance_schedule
STATUS.loop_limit = loop_limit
STATUS.ammo_limit = ammo_limit
self.uris = uris
self.headers = headers
self.marker = get_marker(autocases)
@ -64,20 +66,14 @@ class ComponentFactory():
ammo_gen = missile.UriStyleGenerator(
self.uris,
self.headers,
loop_limit=self.loop_limit,
http_ver=self.http_ver
)
elif self.ammo_file:
ammo_gen = missile.AmmoFileReader(
self.ammo_file,
loop_limit=self.loop_limit
)
ammo_gen = missile.AmmoFileReader(self.ammo_file)
else:
raise StepperConfigurationError(
'Ammo not found. Specify uris or ammo file')
return util.limiter(ammo_gen,
self.ammo_limit
)
return ammo_gen
def get_marker(self):
return self.marker

View File

@ -51,6 +51,9 @@ StepperInfo = namedtuple(
class StepperStatus(object):
'''
Raises StopIteration when limits are reached.
'''
def __init__(self):
self.log = logging.getLogger(__name__)

View File

@ -59,13 +59,12 @@ class UriStyleGenerator(SimpleGenerator):
Generates GET ammo based on given URI list.
'''
def __init__(self, uris, headers, loop_limit=0, http_ver='1.1'):
def __init__(self, uris, headers, http_ver='1.1'):
'''
uris - a list of URIs as strings.
'''
self.ammo_count = 0
self.loop_count = 0
self.loop_limit = loop_limit
self.uri_count = len(uris)
self.missiles = cycle(
[(HttpAmmo(uri, headers, http_ver=http_ver).to_s(), None) for uri in uris])
@ -75,10 +74,7 @@ class UriStyleGenerator(SimpleGenerator):
self.ammo_count += 1
STATUS.ammo_count = self.ammo_count
self.update_loop_count()
if self.loop_limit and self.loop_count > self.loop_limit:
raise StopIteration
else:
yield m
yield m
def update_loop_count(self):
loop_count = self.ammo_count / self.uri_count
@ -94,7 +90,6 @@ class AmmoFileReader(SimpleGenerator):
def __init__(self, filename, loop_limit=0):
self.filename = filename
self.loops = 0
self.loop_limit = loop_limit
def __iter__(self):
with open(self.filename, 'rb') as ammo_file:
@ -117,7 +112,7 @@ class AmmoFileReader(SimpleGenerator):
raise AmmoFileError(
"Error while reading ammo file. Position: %s, header: '%s'" % (ammo_file.tell(), chunk_header))
chunk_header = ammo_file.readline()
if not chunk_header and (self.loops < self.loop_limit or self.loop_limit == 0):
if not chunk_header:
self.loops += 1
STATUS.loop_count = self.loops
ammo_file.seek(0)