question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

custom client from locust documentation doesn't work at all

See original GitHub issue

Looks like while implementing custom client like HttpLocust when adding inline TaskSet class to Locust inline class is not loaded by Locust.

Expected behaviour

Any inline class should be executed by Locust. According to https://docs.locust.io/en/latest/testing-other-systems.html#sample-xml-rpc-locust-client class task_set should be loaded by Locust and all tasks in this class should be executed.

Actual behavior

I have implemented websocket client following this documentation. I have two Locust classes in one file loaded by locust and executed by:

locust -f locustfiles/api_load_tests.py --host=https://my_ip--csv=${report_dir}/report_data --no-web -c ${NUM_CLIENTS} -r ${HATCH_RATE} # ApiVehicleUser ApiMessageUser

Class ApiMessageUser that sets task_set = ApiMessage class attribute is loaded and executed correctly but class ApiVehicleUser which is inline class is not loaded. No error is raised neither.

Environment settings (for bug reports)

  • OS: Ubuntu 16.04.4 LTS
  • Python version: Python 3.5.2
  • Locust version: Locust 0.8

Steps to reproduce (for bug reports)

Bellow is a snippet of the locust file:

class BtsLocust(Locust):
    """
    Provides an Http and websocket clients.
    """

    def __init__(self, *args, **kwargs):
        super(BtsLocust, self).__init__(*args, **kwargs)
        self.ws_client = locust_ws_client.LocustWebSocketClient(self.host)  # this is wrapper like `XmlRpcClient` class


class ApiVehicleUser(BtsLocust):
    # task_set = ApiVehicle
    min_wait = 500
    max_wait = 500


    @task
    class ApiVehicle(TaskSet):

        def on_start(self):
            # some setup

        def on_stop(self):
            # some clean up

    @task
    def here_goes_my_tasks_for_ApiVehicle(self):
        # some setup


class ApiMessage(TaskSet):

    def on_start(self):
        # some setup

    @task
    def here_goes_my_tasks_for_ApiMessage(self):
        # some setup


class ApiMessageUser(HttpLocust):
    task_set = ApiMessage
    min_wait = 500
    max_wait = 500

The thing is that I must have HttpLocust and websocket client at one Locust class to combine tests. If I uncomment # task_set = ApiVehicle then ApiVehicle taks set cannot access to websocket client because for some it is not inherited (and HttpLocust is). So there are few problems over here but the main is mentioned above. So assuming that ApiVehicle will be loaded into Locust all should be fine.

Extra ideas

If anyone have idea how to integrate these two clients using even workarounds I would be glad to do this. I tried to set task_set = ApiVehicle and pass ws_client from outside by __init__ methods but this is messing up too much in Locust super-class and causes too much problems.

I have tried also to add @task decorator to inline class, nothing works.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
cgoldbergcommented, Apr 5, 2018

First of all you guys must investigate these problems and take action

by “you guys”, do you mean the small group of unpaid volunteers helping to maintain the project that provided free software for you?

If so, a quicker option would be for you to step up and take action. The documentation is part of the codebase, and I’d be happy to review a Pull Request with your proposed changes.

2reactions
heymancommented, Apr 11, 2018

@JaniszM If you name the inlined class task_set - like it is in the documentation - I think it should work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing other systems using custom clients — Locust 1.3.1 ...
Locust was built with HTTP as its main target. However, it can easily be extended to load test any request/response based system, by...
Read more >
Python Locust Custom Client Function has no attribute events
Python Locust Custom Client Function has no attribute events ... The locust docs give almost no information on how to use this.
Read more >
4 Useful Advanced Features in Locust | by Ng Wai Foong
Generate custom load shapes (time-based stages); Use other custom clients; Run tasks in parallel. In fact, all of the features mentioned above ...
Read more >
Locust + Python Examples: Variables + Assertions - BlazeMeter
In order to run Locust and Python, you need to have Python installed. (You'll need to download Python first.) Then, all you have...
Read more >
Locust — custom client | by Piotr Grabuszyński - Medium
If you don't know Locust, please start with studying its documentation. Let's get started! Basic HTTP Client: First of all — making HTTP ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found