Exemple #1
0
    def test_requests_csv_quote_escaping(self):
        with mock.patch("locust.rpc.rpc.Server", mocked_rpc()) as server:
            environment = Environment()
            master = environment.create_master_runner(master_bind_host="*",
                                                      master_bind_port=0)
            server.mocked_send(Message("client_ready", None, "fake_client"))

            request_name_dict = {
                "scenario": "get cashes",
                "path": "/cash/[amount]",
                "arguments": [{
                    "size": 1
                }],
            }
            request_name_str = json.dumps(request_name_dict)

            master.stats.get(request_name_str, "GET").log(100, 23455)
            data = {"user_count": 1}
            environment.events.report_to_master.fire(client_id="fake_client",
                                                     data=data)
            master.stats.clear_all()
            server.mocked_send(Message("stats", data, "fake_client"))

            locust.stats.write_csv_files(environment,
                                         self.STATS_BASE_NAME,
                                         full_history=True)
            with open(self.STATS_FILENAME) as f:
                reader = csv.DictReader(f)
                rows = [r for r in reader]
                csv_request_name = rows[0].get("Name")
                self.assertEqual(request_name_str, csv_request_name)
Exemple #2
0
    def test_csv_stats_on_master_from_aggregated_stats(self):
        # Failing test for: https://github.com/locustio/locust/issues/1315
        with mock.patch("locust.rpc.rpc.Server", mocked_rpc()) as server:
            master = MasterLocustRunner(self.environment, [],
                                        master_bind_host="*",
                                        master_bind_port=0)
            server.mocked_send(Message("client_ready", None, "fake_client"))

            master.stats.get("/", "GET").log(100, 23455)
            master.stats.get("/", "GET").log(800, 23455)
            master.stats.get("/", "GET").log(700, 23455)

            data = {"user_count": 1}
            self.environment.events.report_to_master.fire(
                client_id="fake_client", data=data)
            master.stats.clear_all()

            server.mocked_send(Message("stats", data, "fake_client"))
            s = master.stats.get("/", "GET")
            self.assertEqual(700, s.median_response_time)

            locust.stats.write_csv_files(master.stats,
                                         self.STATS_BASE_NAME,
                                         full_history=True)
            self.assertTrue(os.path.exists(self.STATS_FILENAME))
            self.assertTrue(os.path.exists(self.STATS_HISTORY_FILENAME))
            self.assertTrue(os.path.exists(self.STATS_FAILURES_FILENAME))
Exemple #3
0
    def test_csv_stats_on_master_from_aggregated_stats(self):
        # Failing test for: https://github.com/locustio/locust/issues/1315
        with mock.patch("locust.rpc.rpc.Server", mocked_rpc()) as server:
            environment = Environment()
            stats_writer = StatsCSVFileWriter(
                environment, PERCENTILES_TO_REPORT, self.STATS_BASE_NAME, full_history=True
            )
            master = environment.create_master_runner(master_bind_host="*", master_bind_port=0)
            greenlet = gevent.spawn(stats_writer)
            gevent.sleep(_TEST_CSV_STATS_INTERVAL_WAIT_SEC)

            server.mocked_send(Message("client_ready", __version__, "fake_client"))

            master.stats.get("/", "GET").log(100, 23455)
            master.stats.get("/", "GET").log(800, 23455)
            master.stats.get("/", "GET").log(700, 23455)

            data = {"user_count": 1}
            environment.events.report_to_master.fire(client_id="fake_client", data=data)
            master.stats.clear_all()

            server.mocked_send(Message("stats", data, "fake_client"))
            s = master.stats.get("/", "GET")
            self.assertEqual(700, s.median_response_time)

            gevent.kill(greenlet)
            stats_writer.close_files()

            self.assertTrue(os.path.exists(self.STATS_FILENAME))
            self.assertTrue(os.path.exists(self.STATS_HISTORY_FILENAME))
            self.assertTrue(os.path.exists(self.STATS_FAILURES_FILENAME))
            self.assertTrue(os.path.exists(self.STATS_EXCEPTIONS_FILENAME))
Exemple #4
0
 def test_serialize_through_message(self):
     """
     Serialize a RequestStats instance, then serialize it through a Message, 
     and unserialize the whole thing again. This is done "IRL" when stats are sent 
     from workers to master.
     """
     s1 = StatsEntry(self.stats, "test", "GET")
     s1.log(10, 0)
     s1.log(20, 0)
     s1.log(40, 0)
     u1 = StatsEntry.unserialize(s1.serialize())
     
     data = Message.unserialize(Message("dummy", s1.serialize(), "none").serialize()).data
     u1 = StatsEntry.unserialize(data)
     
     self.assertEqual(20, u1.median_response_time)
Exemple #5
0
 def test_serialize_through_message(self):
     """
     Serialize a RequestStats instance, then serialize it through a Message, 
     and unserialize the whole thing again. This is done "IRL" when stats are sent 
     from slaves to master.
     """
     s1 = StatsEntry(self.stats, "test", "GET")
     s1.log(10, 0)
     s1.log(20, 0)
     s1.log(40, 0)
     u1 = StatsEntry.unserialize(s1.serialize())
     
     data = Message.unserialize(Message("dummy", s1.serialize(), "none").serialize()).data
     u1 = StatsEntry.unserialize(data)
     
     self.assertEqual(20, u1.median_response_time)