def test_parse_options(self): parser, options, args = main.parse_options() self.assertEqual('locustfile', options.locustfile) self.assertEqual(None, options.host) # The value: python setup.py 'test' self.assertEqual(['test'], args) parser, options, args = main.parse_options(args=shlex.split('--locustfile=test.py -H http://localhost:5000')) self.assertEqual('test.py', options.locustfile) self.assertEqual('http://localhost:5000', options.host) self.assertEqual([], args)
def setUp(self): global_stats.reset_all() self._slave_report_event_handlers = [ h for h in events.slave_report._handlers ] parser, _, _ = parse_options() args = ["--clients", "10", "--hatch-rate", "10"] opts, _ = parser.parse_args(args) self.options = opts
def setUp(self): global_stats.reset_all() self._slave_report_event_handlers = [h for h in events.slave_report._handlers] parser, _, _ = parse_options() args = [ "--clients", "10", "--hatch-rate", "10" ] opts, _ = parser.parse_args(args) self.options = opts
def test_parameter_parsing(self): with tempfile.NamedTemporaryFile(mode='w') as file: os.environ['LOCUST_LOCUSTFILE'] = "locustfile_from_env" file.write("host host_from_config\nweb-host webhost_from_config") file.flush() parser, _ = parse_options(default_config_files=[file.name]) options = parser.parse_args(['-H','host_from_args']) del os.environ['LOCUST_LOCUSTFILE'] self.assertEqual(options.web_host, 'webhost_from_config') self.assertEqual(options.locustfile, 'locustfile_from_env') self.assertEqual(options.host, 'host_from_args') # overridden
def setUp(self): super(TestWebUI, self).setUp() stats.global_stats.clear_all() parser = parse_options()[0] options = parser.parse_args([])[0] runners.locust_runner = LocustRunner([], options) self._web_ui_server = wsgi.WSGIServer(('127.0.0.1', 0), web.app, log=None) gevent.spawn(lambda: self._web_ui_server.serve_forever()) gevent.sleep(0.01) self.web_port = self._web_ui_server.server_port
def setUp(self): super(TestWebUI, self).setUp() stats.global_stats.clear_all() parser = parse_options(default_config_files=[])[0] self.options = parser.parse_args([]) runners.locust_runner = LocustRunner([], self.options) web.request_stats.clear_cache() self._web_ui_server = pywsgi.WSGIServer(('127.0.0.1', 0), web.app, log=None) gevent.spawn(lambda: self._web_ui_server.serve_forever()) gevent.sleep(0.01) self.web_port = self._web_ui_server.server_port
def start_pressure_test(test_data): global locust_runner_id, host locust_runner_id = test_data["test_id"] host = test_data["host"] locust_count = test_data["locust_count"] hatch_rate = test_data["hatch_rate"] arser, options, arguments = parse_options() WebsiteUser = decorator(test_data=test_data) runners.locust_runner = LocalLocustRunner([WebsiteUser], options) runners.locust_runner.start_hatching(locust_count=locust_count, hatch_rate=hatch_rate) update_running_status(DJANGO_GET_UPDATE_RUNNING_STATUS_URL, locust_runner_id) gevent.spawn_later(test_data["run_time"], time_limit_stop, locust_runner_id)
def test_parse_options(self): parser, options = main.parse_options(args=[ "-f", "locustfile.py", "-c", "100", "-r", "10", "-t", "5m", "--reset-stats", "--stop-timeout", "5", "MyLocustClass", ]) self.assertEqual("locustfile.py", options.locustfile) self.assertEqual(100, options.num_clients) self.assertEqual(10, options.hatch_rate) self.assertEqual("5m", options.run_time) self.assertTrue(options.reset_stats) self.assertEqual(5, options.stop_timeout) self.assertEqual(["MyLocustClass"], options.locust_classes) # check default arg self.assertEqual(8089, options.port)
def setUp(self): self.parser, _ = parse_options(default_config_files=[])
cw_metrics_batch.append(request_response.get_cw_metrics_status_record()) cw_metrics_batch.append(request_response.get_cw_metrics_count_record()) if request_response.get_cw_metrics_response_size_record(): cw_metrics_batch.append(request_response.get_cw_metrics_response_size_record()) if self.usercount: cw_metrics_batch.append(self.usercount.get_metric_data()) self.response_queue.task_done() logging.debug("Queue size:["+str(self.response_queue.qsize())+"]") result['cw_logs_batch']=cw_logs_batch result['cw_metrics_batch']=cw_metrics_batch return result if __name__ == "__main__": parser, options, arguments = main.parse_options() host = '' if options.host: host = options.host #this parameter is supported in case the load generator publishes metrics to CloudWatch in a different AWS account iamrolearn = '' if 'IAM_ROLE_ARN' in os.environ: iamrolearn = os.environ['IAM_ROLE_ARN'] cwconn = CloudWatchConnector(host=host, namespace=CW_METRICS_NAMESPACE,loggroup=CW_LOGS_LOG_GROUP,logstream=CW_LOGS_LOG_STREAM, iamrolearn=iamrolearn) events.locust_start_hatching += cwconn.on_locust_start_hatching events.request_success += cwconn.on_request_success
# -*- coding:utf-8 -*- # Author:lixuecheng from locust.main import main, parse_options parse_options() main()
cw_metrics_batch.append(request_response.get_cw_metrics_count_record()) if request_response.get_cw_metrics_response_size_record(): cw_metrics_batch.append(request_response.get_cw_metrics_response_size_record()) if self.usercount: cw_metrics_batch.append(self.usercount.get_metric_data()) self.response_queue.task_done() log.debug("Queue size:["+str(self.response_queue.qsize())+"]") result['cw_logs_batch']=cw_logs_batch result['cw_metrics_batch']=cw_metrics_batch return result if __name__ == "__main__": #parser, options, arguments = main.parse_options() parser, options = main.parse_options() host = '' if options.host: host = options.host #this parameter is supported in case the load generator publishes metrics to CloudWatch in a different AWS account iamrolearn = '' if 'IAM_ROLE_ARN' in os.environ: iamrolearn = os.environ['IAM_ROLE_ARN'] cwconn = CloudWatchConnector(host=host, namespace=CW_METRICS_NAMESPACE,loggroup=CW_LOGS_LOG_GROUP,logstream=CW_LOGS_LOG_STREAM, iamrolearn=iamrolearn) events.locust_start_hatching += cwconn.on_locust_start_hatching events.request_success += cwconn.on_request_success
def setUp(self): self.parser, _, _ = parse_options()
def _load_options(self): try: options = parse_options() self.host = options[1].host except Exception as e: logger.error(e)
from edfi_performance.config import get_config_value from edfi_performance.tasks.change_query import EdFiChangeQueryTestBase, EdFiChangeQueryTaskSequence, \ EdFiChangeQueryTestTerminator # Import modules under tasks.change_query package so *ChangeQueryTest classes are registered tasks_submodules = [ name for _, name, _ in pkgutil.iter_modules( [os.path.join('edfi_performance', 'tasks', 'change_query')], prefix='edfi_performance.tasks.change_query.') ] for mod_name in tasks_submodules: importlib.import_module(mod_name) # Collect *ChangeQueryTest classes and append them to # EdFiChangeQueryTaskSequence.tasks _, opts, args = parse_options() subclasses = EdFiChangeQueryTestBase.__subclasses__() valid_names = set() for subclass in subclasses: name = subclass.__name__ valid_names.add(name) if len(args) > 0 and name not in args: # Skip this class if individual tests have been specified and this # isn't one of them continue EdFiChangeQueryTaskSequence.tasks.append(subclass) EdFiChangeQueryTaskSequence.tasks.append(EdFiChangeQueryTestTerminator) class EdFiChangeQueryTestMixin(object):
def main(user_params=None, common_param=None): parser, options, arguments = parse_options() # setup logging setup_logging(options.loglevel, options.logfile) logger = logging.getLogger(__name__) if options.show_version: print("Locust %s" % (version, )) sys.exit(0) locustfile = find_locustfile(options.locustfile) if not locustfile: logger.error( "Could not find any locustfile! Ensure file ends in '.py' and see --help for available options." ) sys.exit(1) if locustfile == "locust.py": logger.error( "The locustfile must not be named `locust.py`. Please rename the file and try again." ) sys.exit(1) docstring, locusts = load_locustfile(locustfile) if options.list_commands: console_logger.info("Available Locusts:") for name in locusts: console_logger.info(" " + name) sys.exit(0) if not locusts: logger.error("No Locust class found!") sys.exit(1) # make sure specified Locust exists if arguments: missing = set(arguments) - set(locusts.keys()) if missing: logger.error("Unknown Locust(s): %s\n" % (", ".join(missing))) sys.exit(1) else: names = set(arguments) & set(locusts.keys()) locust_classes = [locusts[n] for n in names] else: # list() call is needed to consume the dict_view object in Python 3 locust_classes = list(locusts.values()) if options.show_task_ratio: console_logger.info("\n Task ratio per locust class") console_logger.info("-" * 80) print_task_ratio(locust_classes) console_logger.info("\n Total task ratio") console_logger.info("-" * 80) print_task_ratio(locust_classes, total=True) sys.exit(0) if options.show_task_ratio_json: from json import dumps task_data = { "per_class": get_task_ratio_dict(locust_classes), "total": get_task_ratio_dict(locust_classes, total=True) } console_logger.info(dumps(task_data)) sys.exit(0) if not options.no_web and not options.slave: # spawn web greenlet logger.info("Starting web monitor at %s:%s" % (options.web_host or "*", options.port)) main_greenlet = gevent.spawn(web.start, locust_classes, options) if not options.master and not options.slave: if user_params: runners.locust_runner = ParameterizableLocustRunner( locust_classes, options, user_params, common_param) else: runners.locust_runner = LocalLocustRunner(locust_classes, options) # spawn client spawning/hatching greenlet if options.no_web: runners.locust_runner.start_hatching(wait=True) main_greenlet = runners.locust_runner.greenlet elif options.master: runners.locust_runner = MasterLocustRunner(locust_classes, options) if options.no_web: while len(runners.locust_runner.clients.ready ) < options.expect_slaves: logging.info( "Waiting for slaves to be ready, %s of %s connected", len(runners.locust_runner.clients.ready), options.expect_slaves) time.sleep(1) runners.locust_runner.start_hatching(options.num_clients, options.hatch_rate) main_greenlet = runners.locust_runner.greenlet elif options.slave: try: runners.locust_runner = SlaveLocustRunner(locust_classes, options) main_greenlet = runners.locust_runner.greenlet except socket.error as e: logger.error("Failed to connect to the Locust master: %s", e) sys.exit(-1) if not options.only_summary and (options.print_stats or (options.no_web and not options.slave)): # spawn stats printing greenlet gevent.spawn(stats_printer) if options.csvfilebase: gevent.spawn(stats_writer, options.csvfilebase) def shutdown(code=0): """ Shut down locust by firing quitting event, printing/writing stats and exiting """ logger.info("Shutting down (exit code %s), bye." % code) events.quitting.fire() print_stats(runners.locust_runner.request_stats) print_percentile_stats(runners.locust_runner.request_stats) if options.csvfilebase: write_stat_csvs(options.csvfilebase) print_error_report() sys.exit(code) # install SIGTERM handler def sig_term_handler(): logger.info("Got SIGTERM signal") shutdown(0) gevent.signal(gevent.signal.SIGTERM, sig_term_handler) try: logger.info("Starting Locust %s" % version) main_greenlet.join() code = 0 if len(runners.locust_runner.errors): code = 1 shutdown(code=code) except KeyboardInterrupt as e: shutdown(0)