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

Fix Incorrectly Updating Stat History #2972

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion locust/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def get_html_report(
{**exc, "nodes": ", ".join(exc["nodes"])} for exc in environment.runner.exceptions.values()
]

update_stats_history(environment.runner)
if stats.history and stats.history[-1]["time"] < end_time:
update_stats_history(environment.runner, end_time)
history = stats.history

is_distributed = isinstance(environment.runner, MasterRunner)
Expand Down
7 changes: 4 additions & 3 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,9 @@ def sort_stats(stats: dict[Any, S]) -> list[S]:
return [stats[key] for key in sorted(stats.keys())]


def update_stats_history(runner: Runner) -> None:
def update_stats_history(runner: Runner, timestamp: str | None = None) -> None:
stats = runner.stats
timestamp = format_utc_timestamp(time.time())
timestamp = timestamp or format_utc_timestamp(time.time())
current_response_time_percentiles = {
f"response_time_percentile_{percentile}": [
timestamp,
Expand All @@ -929,7 +929,8 @@ def stats_history(runner: Runner) -> None:
while True:
if not runner.stats.total.use_response_times_cache:
break
if runner.state != "stopped":

if runner.state != "ready" and runner.state != "stopped":
update_stats_history(runner)

gevent.sleep(HISTORY_STATS_INTERVAL_SEC)
Expand Down
3 changes: 2 additions & 1 deletion locust/test/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,12 @@ def test_requests_csv_quote_escaping(self):
def test_stats_history(self):
env1 = Environment(events=locust.events, catch_exceptions=False)
runner1 = env1.create_master_runner("127.0.0.1", 5558)
runner1.state = "running"
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)
gevent.sleep(0.1)
hs1 = runner1.stats.history
hs2 = runner2.stats.history
gevent.kill(greenlet1)
Expand Down