From 35f63fc060e8d0af2fd3606c52627a71808bd402 Mon Sep 17 00:00:00 2001 From: Andrew Baldwin Date: Tue, 5 Sep 2023 19:43:57 +0200 Subject: [PATCH] Add multiple host tests for test_stats --- locust/test/test_stats.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/locust/test/test_stats.py b/locust/test/test_stats.py index bdc808c4a1..7a88bb2e31 100644 --- a/locust/test/test_stats.py +++ b/locust/test/test_stats.py @@ -283,6 +283,21 @@ def test_error_grouping(self): self.stats.log_error("GET", "/some-path", "", Exception("Third exception!")) self.assertEqual(3, len(self.stats.errors)) + def test_error_grouping_with_multiple_hosts(self): + # reset stats + self.stats = RequestStats() + + self.stats.log_error("GET", "/some-path", "http://127.0.0.1:1", Exception("Exception!")) + self.stats.log_error("GET", "/some-path", "http://127.0.0.1:2", Exception("Exception!")) + self.assertEqual(2, len(self.stats.errors)) + self.assertEqual(1, list(self.stats.errors.values())[0].occurrences) + self.assertEqual(1, list(self.stats.errors.values())[1].occurrences) + + self.stats.log_error("GET", "/some-path", "http://127.0.0.1:1", Exception("Another exception!")) + self.stats.log_error("GET", "/some-path", "http://127.0.0.1:1", Exception("Another exception!")) + self.stats.log_error("GET", "/some-path", "http://127.0.0.1:2", Exception("Third exception!")) + self.assertEqual(4, len(self.stats.errors)) + def test_error_grouping_errors_with_memory_addresses(self): # reset stats self.stats = RequestStats() @@ -599,6 +614,23 @@ def test_stats_history(self): self.assertEqual(1, len(hs1)) self.assertEqual(0, len(hs2)) + def test_csv_multiple_hosts(self): + class UserOne(User): + host = "http://127.0.0.1:1" + + class UserTwo(User): + host = "http://127.0.0.1:2" + + self.environment.user_classes = [UserOne, UserTwo] + + _write_csv_files(self.environment, self.STATS_BASE_NAME) + + with open(self.STATS_HISTORY_FILENAME) as f: + reader = csv.DictReader(f) + rows = [r for r in reader] + + self.assertIn("Host", rows[0]) + class TestStatsEntryResponseTimesCache(unittest.TestCase): def setUp(self, *args, **kwargs):