def test_duration_calc(self): f = get_fire_dict() f['load'] = [ ['line', 1, 10, '2m'], ['step', 100, 150, 5, '1m'], ] # line duration 2m = 2 * 60 * 1000 = 120000 ms # steps duration ((150 - 100) / 5 + 1) * 1 * 60 * 1000 = 660000 ms self.assertEqual(fire_duration(f), 120000 + 660000)
def build_test(test_cfg, args=None): '''Create dirs tree, phantom.cfg and ammo.stpd Args: test_cfg: dict, test config. default: dict, default settings and validation rules. args: argparse obj instance. ''' logger = logging.getLogger('root') now = datetime.datetime.now() orig_wd = os.getcwd() ammo_from_arg = False test_http_cntx = None if 'ammo' in test_cfg: test_http_cntx = test_cfg['ammo'].get('http_context', None) for idx, f in enumerate(test_cfg['fire']): try: validate(f, tgt='fire') except validictory.validator.ValidationError, e: raise FireEmergencyExit('Error in parsing fire dict:\n%s' % e) # get absolute ammo path before chdir if not ammo_from_arg: if args and args.ammo_file: ammo_from_arg = os.path.abspath(args.ammo_file) ammo_path = ammo_from_arg else: ammo_path = f['input_file'] if not os.path.isfile(ammo_path): raise FireEmergencyExit('No such ammo file: %s' % ammo_path) try: pbar_max = f['total_dur'] = fire_duration(f) except StepperSchemaFormat, e: msg = [ 'Malformed shcema format in fire: %s' % f['name'], 'in \'%s\' > \'%s\'' % (f['name'], e.value['schema']) ] raise FireEmergencyExit(msg)