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

cant show html chart version locust 2.4.0 #1908

Closed
4672192zq opened this issue Oct 20, 2021 · 1 comment
Closed

cant show html chart version locust 2.4.0 #1908

4672192zq opened this issue Oct 20, 2021 · 1 comment
Labels

Comments

@4672192zq
Copy link

Describe the bug

Headless mode cannot view charts-html

Expected behavior

The generated htlm can be displayed normally

Actual behavior

image

Steps to reproduce

`from locust import HttpUser,TaskSet,between,task,FastHttpUser

from locust import LoadTestShape

headers = {"Content-Type": "application/json", "app_id": "101"}
class UserBehavior(TaskSet):

def on_start(self):
    pass
@task
def test_health(self):
    '''查询全部'''

    url = '/statapi/health'

    with self.client.get(url,catch_response=True,timeout=3) as response:
        # print("=====", response)
        if response.status_code!=200:
            response.failure('Failed!')


def on_stop(self):
    pass

class MyCustomShape(LoadTestShape):

stages = [
    {"time": 10, "users": 100, "spawn_rate": 50},
    {"time": 30, "users": 200, "spawn_rate": 50},

]
def tick(self):
    run_time = self.get_run_time()
    print("run_time:",run_time)
    for stage in self.stages:

        if run_time < stage['time']:
            print('11111',stage['time'])
            tick_data = (stage['users'],stage['spawn_rate'])
            print('tick_data', tick_data)
            return tick_data
    return None


    # return None

class WebsiteUser(FastHttpUser):
tasks = [UserBehavior]

wait_time = between(1, 1)

`

Environment

  • OS:
  • Python version:3.9
  • Locust version: (please dont file issues for anything but the most recent release or prerelease builds)
  • Locust command line that you ran:
  • Locust file contents (anonymized if necessary):
@4672192zq 4672192zq added the bug label Oct 20, 2021
@AlexisC0de
Copy link

AlexisC0de commented Oct 21, 2021

in case of environment.shape_class code path, stats_history won't be filled, thus preventing the Charts graph to be displayed in the html report.
It seems that the stats_history runner launch should be moved before start_automatic_run() .


diff --git a/locust/main.py b/locust/main.py
index 9c0bdc2..f5819d2 100644

--- a/locust/main.py
+++ b/locust/main.py
@@ -341,6 +341,8 @@ def main():
         stats_printer_greenlet = gevent.spawn(stats_printer(runner.stats))
         stats_printer_greenlet.link_exception(greenlet_exception_handler)
 
+    gevent.spawn(stats_history, runner)
+
     def start_automatic_run():
         if options.master:
             # wait for worker nodes to connect
@@ -408,8 +410,6 @@ def main():
     if options.csv_prefix:
         gevent.spawn(stats_csv_writer.stats_writer).link_exception(greenlet_exception_handler)
 
-    gevent.spawn(stats_history, runner)
-
     def shutdown():
         """
         Shut down locust by firing quitting event, printing/writing stats and exiting

(this complete commit 08bc7e9)

AlexisC0de pushed a commit to AlexisC0de/locust that referenced this issue Oct 21, 2021
in case of environment.shape_class code path, stats_history won't be
filled, thus preventing the Charts graph to be displayed in the html report

(complete commit 08bc7e9)
AlexisC0de pushed a commit to AlexisC0de/locust that referenced this issue Oct 21, 2021
in case of environment.shape_class code path, stats_history won't be
filled, thus preventing the Charts graph to be displayed in the html report

(complete commit 08bc7e9)
@cyberw cyberw closed this as completed in 30dc99d Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants