Example #1
0
    def setUp(self):
        super().setUp()
        tls_cert, tls_key = create_tls_cert("127.0.0.1")
        self.tls_cert_file = NamedTemporaryFile(delete=False)
        self.tls_key_file = NamedTemporaryFile(delete=False)
        with open(self.tls_cert_file.name, "w") as f:
            f.write(tls_cert.decode())
        with open(self.tls_key_file.name, "w") as f:
            f.write(tls_key.decode())

        parser = get_parser(default_config_files=[])
        options = parser.parse_args([
            "--tls-cert",
            self.tls_cert_file.name,
            "--tls-key",
            self.tls_key_file.name,
        ])
        self.runner = Runner(self.environment)
        self.stats = self.runner.stats
        self.web_ui = self.environment.create_web_ui("127.0.0.1",
                                                     0,
                                                     tls_cert=options.tls_cert,
                                                     tls_key=options.tls_key)
        gevent.sleep(0.01)
        self.web_port = self.web_ui.server.server_port
Example #2
0
 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 = get_parser(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
Example #3
0
    def setUp(self):
        super(TestWebUI, self).setUp()

        parser = get_parser(default_config_files=[])
        self.environment.options = parser.parse_args([])
        self.stats = self.environment.stats

        self.web_ui = self.environment.create_web_ui("127.0.0.1", 0)
        self.web_ui.app.view_functions["request_stats"].clear_cache()
        gevent.sleep(0.01)
        self.web_port = self.web_ui.server.server_port
Example #4
0
 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 = get_parser(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
Example #5
0
    def setUp(self):
        super().setUp()

        parser = get_parser(default_config_files=[])
        options = parser.parse_args(["--web-auth", "john:doe"])
        self.runner = Runner(self.environment)
        self.stats = self.runner.stats
        self.web_ui = self.environment.create_web_ui("127.0.0.1", 0, auth_credentials=options.web_auth)
        self.web_ui.app.view_functions["request_stats"].clear_cache()
        gevent.sleep(0.01)
        self.web_port = self.web_ui.server.server_port
Example #6
0
    def setUp(self):
        super(TestWebUI, self).setUp()

        parser = get_parser(default_config_files=[])
        self.environment.options = parser.parse_args([])
        self.runner = LocustRunner(self.environment, [])
        self.stats = self.runner.stats

        self.web_ui = WebUI(self.environment)
        self.web_ui.app.view_functions["request_stats"].clear_cache()

        gevent.spawn(lambda: self.web_ui.start("127.0.0.1", 0))
        gevent.sleep(0.01)
        self.web_port = self.web_ui.server.server_port
Example #7
0
    def setUp(self):
        super().setUp()
        self.remove_files_if_exists()

        parser = get_parser(default_config_files=[])
        self.environment.parsed_options = parser.parse_args(["--csv", self.STATS_BASE_NAME, "--csv-full-history"])
        self.stats = self.environment.stats
        self.stats.CSV_STATS_INTERVAL_SEC = 0.02

        locust.stats.CSV_STATS_INTERVAL_SEC = 0.1
        self.stats_csv_writer = StatsCSVFileWriter(
            self.environment, stats.PERCENTILES_TO_REPORT, self.STATS_BASE_NAME, full_history=True
        )
        self.web_ui = self.environment.create_web_ui("127.0.0.1", 0, stats_csv_writer=self.stats_csv_writer)
        self.web_ui.app.view_functions["request_stats"].clear_cache()
        gevent.sleep(0.01)
        self.web_port = self.web_ui.server.server_port
Example #8
0
    def setUp(self):
        super(TestWebUI, self).setUp()

        parser = get_parser(default_config_files=[])
        self.environment.parsed_options = parser.parse_args([])
        self.stats = self.environment.stats

        self.web_ui = self.environment.create_web_ui("127.0.0.1", 0)
        self.web_ui.app.view_functions["request_stats"].clear_cache()

        # This would normally be called in locustfile
        add_listener()

        # Fire locust init event which is normally done in main, after import of locustfile.py
        self.environment.events.init.fire(environment=self.environment,
                                          runner=self.runner,
                                          web_ui=self.web_ui)

        gevent.sleep(0.01)
        self.web_port = self.web_ui.server.server_port
Example #9
0
 def setUp(self):
     self.parser = get_parser(default_config_files=[])