def main(num_agents, rampup, interval, duration, tc_xml_filename, log_msgs, output_dir=None, test_name=None, is_block=True): runtime_stats = {} error_queue = [] interval = interval / 1000.0 # convert from millisecs to secs # create a load manager lm = LoadManager(num_agents, interval, rampup, log_msgs, runtime_stats, error_queue, output_dir, test_name, is_block) # load the test cases try: cases = xmlparse.load_xml_cases(tc_xml_filename) for req in cases: lm.add_req(req) except Exception, e: print 'ERROR: can not parse testcase file: %s' % e sys.exit(1)
def main(num_agents, rampup, interval, duration, tc_xml_filename, log_msgs, output_dir=None, test_name=None): if not config.HTTP_DEBUG: # turn off stdout and stderr sys.stdout = open(os.devnull, 'w') sys.stderr = open(os.devnull, 'w') runtime_stats = {} error_queue = [] interval = interval / 1000.0 # convert from millisecs to secs if test_name: if output_dir: output_dir = output_dir + '/' + test_name # create a load manager lm = LoadManager(num_agents, interval, rampup, log_msgs, runtime_stats, error_queue, output_dir, test_name,) # load the test cases try: cases = xmlparse.load_xml_cases(tc_xml_filename) for req in cases: lm.add_req(req) except Exception, e: print 'ERROR: can not parse testcase file: %s' % e sys.exit(1)
def get_task_template(): try: template_file = template_dir + os.sep + 'testcases.xml' cases = xmlparse.load_xml_cases(template_file) return load_str(template_file) except Exception as e: print('ERROR: can not parse testcase file: %s' % e) raise UnicornException(name='can not parse testcase file')
def on_run(self, evt): # reset stats and errors in case there was a previous run since startup self.runtime_stats = {} self.error_queue = [] # get values from UI controls num_agents = self.num_agents_spin.GetValue() interval = self.interval_spin.GetValue() / 1000.0 # convert millisecs to secs rampup = self.rampup_spin.GetValue() duration = self.duration_spin.GetValue() log_msgs = self.log_msgs_checkbox.GetValue() test_name = self.name_textbox.GetValue() if test_name == 'Test Name': # user didn't enter a Test Name test_name = None if test_name: if self.output_dir: self.output_dir = self.output_dir + '/' + test_name # create a load manager self.lm = LoadManager(num_agents, interval, rampup, log_msgs, self.runtime_stats, self.error_queue, self.output_dir, test_name) # load the test cases try: cases = xmlparse.load_xml_cases(self.tc_xml_filename) for req in cases: self.lm.add_req(req) except Exception as e: print('ERROR: can not parse testcase file: %s' % e) dial = wx.MessageDialog(None, 'Invalid testcase file', 'Error', wx.OK | wx.ICON_ERROR) dial.ShowModal() cases = None if cases: # only run if we have valid cases self.start_time = time.time() # start the load manager self.lm.setDaemon(True) self.lm.start() # start a thread to stop execution when the test duration lapses self.stopper = Stopper(self, duration) self.stopper.setDaemon(True) self.stopper.start() self.rt_mon = RTMonitor(self.start_time, self.runtime_stats, self.error_queue, self.agents_statlist, self.total_statlist, self.error_list) self.rt_mon.error_list.Clear() self.rt_mon.setDaemon(True) self.rt_mon.start() self.switch_status(True)
def main(num_agents, rampup, interval, duration, tc_xml_filename, log_msgs, output_dir=None, test_name=None): runtime_stats = {} error_queue = [] interval = interval / 1000.0 # convert from millisecs to secs # create a load manager lm = LoadManager(num_agents, interval, rampup, log_msgs, runtime_stats, error_queue, output_dir, test_name) # load the test cases try: cases = xmlparse.load_xml_cases(tc_xml_filename) for req in cases: lm.add_req(req) except Exception, e: print 'ERROR: can not parse testcase file: %s' % e sys.exit(1)
def main(num_agents, rampup, interval, duration, tc_xml_filename, log_msgs, output_dir=None, test_name=None): if not config.HTTP_DEBUG: # turn off stdout and stderr sys.stdout = open(os.devnull, 'w') sys.stderr = open(os.devnull, 'w') runtime_stats = {} error_queue = [] interval = interval / 1000.0 # convert from millisecs to secs if test_name: if output_dir: output_dir = output_dir + '/' + test_name # create a load manager lm = LoadManager( num_agents, interval, rampup, log_msgs, runtime_stats, error_queue, output_dir, test_name, ) # load the test cases try: cases = xmlparse.load_xml_cases(tc_xml_filename) for req in cases: lm.add_req(req) except Exception, e: print 'ERROR: can not parse testcase file: %s' % e sys.exit(1)
def main(num_agents, rampup, interval, duration, tc_xml_filename, log_msgs, output_dir=None, test_name=None): runtime_stats = {} error_queue = [] interval = interval / 1000.0 # convert from millisecs to secs # create a load manager lm = LoadManager(num_agents, interval, rampup, log_msgs, runtime_stats, error_queue, output_dir, test_name) # load the test cases try: cases = xmlparse.load_xml_cases(tc_xml_filename) for req in cases: lm.add_req(req) except Exception as e: print('ERROR: can not parse testcase file: %s' % e) sys.exit(1) start_time = time.time() # start the load manager lm.setDaemon(True) lm.start() reporter = RuntimeReporter(duration, runtime_stats) while (time.time() < start_time + duration): refresh_rate = 0.5 time.sleep(refresh_rate) # when all agents are started, start displaying the progress bar and stats if lm.agents_started: elapsed_secs = time.time() - start_time reporter.refresh(elapsed_secs, refresh_rate) lm.stop() # wait until the result generator is finished if config.GENERATE_RESULTS: while lm.results_gen.is_alive(): time.sleep(0.1) print('Done.')
def main(num_agents, rampup, interval, duration, tc_xml_filename, log_msgs, output_dir=None, test_name=None): if not config.HTTP_DEBUG: # turn off stdout and stderr sys.stdout = open(os.devnull, 'w') sys.stderr = open(os.devnull, 'w') runtime_stats = {} error_queue = [] interval = interval / 1000.0 # convert from millisecs to secs if test_name: if output_dir: output_dir = output_dir + '/' + test_name # create a load manager lm = LoadManager( num_agents, interval, rampup, log_msgs, runtime_stats, error_queue, output_dir, test_name, ) # load the test cases try: cases = xmlparse.load_xml_cases(tc_xml_filename) for req in cases: lm.add_req(req) except Exception as e: print('ERROR: can not parse testcase file: %s' % e) sys.exit(1) start_time = time.time() # start the load manager lm.setDaemon(True) lm.start() # wait for the test duration to lapse time.sleep(duration) elapsed_secs = time.time() - start_time lm.stop() # wait until the result generator is finished while lm.results_gen.is_alive(): time.sleep(.10) ids = runtime_stats.keys() agg_count = sum([runtime_stats[id].count for id in ids]) # total req count agg_total_latency = sum([runtime_stats[id].total_latency for id in ids]) agg_error_count = sum([runtime_stats[id].error_count for id in ids]) total_bytes_received = sum([runtime_stats[id].total_bytes for id in ids]) avg_resp_time = agg_total_latency / agg_count # avg response time since start avg_throughput = float( agg_count) / elapsed_secs # avg throughput since start response_xml = """\ <results> <summary-results> <requests>%d</requests> <errors>%d</errors> <avg-response-time>%.3f</avg-response-time> <avg-throughput>%.2f</avg-throughput> <bytes-received>%i</bytes-received> </summary-results> """ % (agg_count, agg_error_count, avg_resp_time, avg_throughput, total_bytes_received) for id in runtime_stats: response_xml += """ <agent-results> <agent-num>%d</agent-num> <requests>%d</requests> <errors>%d</errors> <avg-response-time>%.3f<avg-response-time> <bytes-received>%i</bytes-received> </agent-results> """ % ( id + 1, runtime_stats[id].count, runtime_stats[id].error_count, runtime_stats[id].avg_latency, runtime_stats[id].total_bytes) response_xml += """ </results>""" sys.stdout = original_stdout # temporarily turn on stdout print(response_xml) sys.stdout = open(os.devnull, 'w') # turn off stdout again return response_xml