How to use the locust.between function in locust

To help you get started, we’ve selected a few locust examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moinwiki / moin / contrib / loadtesting / locust / locustfile.py View on Github external
"extra_meta_text": '{"namespace": "","rev_number": 1}',
                                     })
        if response.status_code != 200:
            print('%s: response.status_code = %s' % (sys._getframe().f_lineno, response.status_code))

    @seq_task(10)
    def logout(self):
        response = self.client.get("/+logout?logout_submit=1")
        if response.status_code != 200:
            print('%s: response.status_code = %s' % (sys._getframe().f_lineno, response.status_code))


class WebsiteUser(HttpLocust):

    task_set = UserSequence
    wait_time = between(2, 3)  # min_wait and max_wait deprecated since version 0.13

    def setup(self):
        """create Home and users/Home items"""
        parser = argparse.ArgumentParser()
        parser.add_argument('--host', '-H')
        args, unknown = parser.parse_known_args()
        host = args.host
        if host:
            if host.endswith('/'):
                host = host[:-1]

            print('==== creating Home and users/Home ====')
            url = host + "/+modify/users/Home?contenttype=text%2Fx.moin.wiki%3Bcharset%3Dutf-8&itemtype=default&template="
            data = urllib.parse.urlencode({"content_form_data_text": "= users/Home =\n * created by Locust",
                                     "comment": "",
                                     "submit": "OK",
github jaimeteb / chatto / utils / performance-test / locustfile.py View on Github external
self.client.post("/channels/rest", json={
            "sender": self.chatto_name,
            "text": "bad",
        })

    @task
    def yes(self):
        self.client.post("/channels/rest", json={
            "sender": self.chatto_name,
            "text": "yes",
        })


class User(HttpUser):
    tasks = [ChattoUser]
    wait_time = between(1, 2)
github locustio / locust / examples / semaphore_wait.py View on Github external
all_locusts_spawned.release()

events.hatch_complete += on_hatch_complete

class UserTasks(TaskSet):
    def on_start(self):
        all_locusts_spawned.wait()
        self.wait()
    
    @task
    def index(self):
        self.client.get("/")
    
class WebsiteUser(HttpLocust):
    host = "http://127.0.0.1:8089"
    wait_time = between(2, 5)
    task_set = UserTasks
github httprunner / httprunner / httprunner / ext / locust / locustfile.py View on Github external
import random

from locust import task, HttpUser, between

from httprunner.ext.locust import prepare_locust_tests


class HttpRunnerUser(HttpUser):
    host = ""
    wait_time = between(5, 15)

    def on_start(self):
        locust_tests = prepare_locust_tests()
        self.testcase_runners = [
            testcase().with_session(self.client) for testcase in locust_tests
        ]

    @task
    def test_any(self):
        test_runner = random.choice(self.testcase_runners)
        try:
            test_runner.run()
        except Exception as ex:
            self.environment.events.request_failure.fire(
                request_type="Failed",
                name=test_runner.config.name,
github locustio / locust / examples / multiple_hosts.py View on Github external
class UserTasks(TaskSet):
    # but it might be convenient to use the @task decorator
    @task
    def index(self):
        self.locust.client.get("/")
    
    @task
    def index_other_host(self):
        self.locust.api_client.get("/stats/requests")
    
class WebsiteUser(MultipleHostsLocust):
    """
    Locust user class that does requests to the locust web server running on localhost
    """
    host = "http://127.0.0.1:8089"
    wait_time = between(2, 5)
    task_set = UserTasks
github locustio / locust / examples / dynamice_user_credentials.py View on Github external
]

class UserBehaviour(TaskSet):
    def on_start(self):
        if len(USER_CREDENTIALS) > 0:
            user, passw = USER_CREDENTIALS.pop()
            self.client.post("/login", {"username":user, "password":passw})
    
    @task
    def some_task(self):
        # user should be logged in here (unless the USER_CREDENTIALS ran out)
        self.client.get("/protected/resource")

class User(HttpLocust):
    task_set = UserBehaviour
    wait_time = between(5, 60)
github locustio / locust / examples / fast_http_locust.py View on Github external
    @task
    def index(self):
        self.client.get("/")
    
    @task
    def stats(self):
        self.client.get("/stats/requests")

    
class WebsiteUser(FastHttpLocust):
    """
    Locust user class that does requests to the locust web server running on localhost,
    using the fast HTTP client
    """
    host = "http://127.0.0.1:8089"
    wait_time = between(2, 5)
    task_set = UserTasks
github locustio / locust / examples / basic.py View on Github external
class UserTasks(TaskSet):
    # one can specify tasks like this
    tasks = [index, stats]
    
    # but it might be convenient to use the @task decorator
    @task
    def page404(self):
        self.client.get("/does_not_exist")
    
class WebsiteUser(HttpLocust):
    """
    Locust user class that does requests to the locust web server running on localhost
    """
    host = "http://127.0.0.1:8089"
    wait_time = between(2, 5)
    task_set = UserTasks
github plone / plone.restapi / performance / images.py View on Github external
image_10mb_get_scale_preview: 1,
        image_10mb_get_scale_tile: 1,
    }

    def on_start(self):
        # login(self)
        pass

    def on_stop(self):
        # logout(self)
        pass


class WebsiteUser(HttpUser):
    task_set = UserBehavior
    wait_time = between(5.0, 9.0)
github DevopsArtFactory / klocust / pkg / klocust / _default_templates / tasks / locustfile.py View on Github external
######################################################################
    @task(60)
    def index(self):
        self.get("/")

    @task(40)
    def health(self):
        self.get("/health")


class WebsiteUser(HttpUser):
    tasks = [WebsiteTasks]

    # If you want no wait time between tasks
    # wait_time = constant(0)
    wait_time = between(1, 2)

    # default target host
    host = "http://www.example.com"