Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for stats_history #1538

Merged
merged 4 commits into from
Aug 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions locust/test/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from locust.rpc.protocol import Message
from locust.stats import CachedResponseTimes, RequestStats, StatsEntry, diff_response_time_dicts, PERCENTILES_TO_REPORT
from locust.stats import StatsCSVFileWriter
from locust.stats import stats_history
from locust.test.testcases import LocustTestCase
from locust.user.inspectuser import get_task_ratio_dict

Expand Down Expand Up @@ -479,6 +480,21 @@ def test_requests_csv_quote_escaping(self):
csv_request_name = rows[0].get("Name")
self.assertEqual(request_name_str, csv_request_name)

def test_stats_history(self):
env1 = Environment(events=locust.events, catch_exceptions=False)
runner1 = env1.create_master_runner("127.0.0.1", 5558)
env2 = Environment(events=locust.events, catch_exceptions=False)
runner2 = env2.create_worker_runner("127.0.0.1", 5558)
greenlet1 = gevent.spawn(stats_history, runner1)
greenlet2 = gevent.spawn(stats_history, runner2)
gevent.sleep(1)
hs1 = runner1.stats.history
hs2 = runner2.stats.history
gevent.kill(greenlet1)
gevent.kill(greenlet2)
self.assertEqual(1, len(hs1))
self.assertEqual(0, len(hs2))


class TestStatsEntryResponseTimesCache(unittest.TestCase):
def setUp(self, *args, **kwargs):
Expand Down