How to use the locust.TaskSet 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 edx-unsupported / edx-load-tests / loadtests / course_import / locustfile.py View on Github external
settings.init(
    __name__,
    required_data=[
        'CMS_USER_EMAIL',
        'TEST_FILE',
        'NUM_PARALLEL_COURSES',
    ],
    required_secrets=[
        'CMS_USER_PASSWORD',
    ],
)

markers.install_event_markers()


class CourseImport(TaskSet):
    "Course import task set -- creates course and imports tarballs."

    def on_start(self):
        "Setup method; log in to studio and create courses."

        self.login()

        for i in xrange(settings.data['NUM_PARALLEL_COURSES']):
            self.create_course(i)

    def login(self):
        "Log in to CMS."

        if settings.data.get('BASIC_AUTH_USER') is not None:
            self.client.auth = (
                settings.data['BASIC_AUTH_USER'],
github edx-unsupported / edx-load-tests / loadtests / course_discovery / locustfile.py View on Github external
from locust import HttpLocust, task, TaskSet
from locust.clients import HttpSession

from helpers import settings, markers
from helpers.api import LocustEdxRestApiClient

settings.init(
    __name__,
    required_data=['programs'],
    required_secrets=['oauth'],
)

markers.install_event_markers()


class SelfInterruptingTaskSet(TaskSet):
    @task(1)
    def stop(self):
        self.interrupt()


class CatalogTaskSet(SelfInterruptingTaskSet):
    catalog_id = 1

    @task(20)
    def get_catalog_courses(self):
        """Retrieve all courses associated with a catalog."""
        self.client.api.v1.catalogs(self.catalog_id).courses.get()

    @task(10)
    def list_courses_with_query(self):
        """Query the courses."""
github mitmproxy / mitmproxy / test / mitmproxy / data / test_flow_export / locust_get.py View on Github external
from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):
    def on_start(self):
        ''' on_start is called when a Locust start before any task is scheduled '''
        self.path()

    @task()
    def path(self):
        url = self.locust.host + '/path'

        headers = {
            'header': 'qvalue',
            'content-length': '7',
        }

        params = {
            'a': ['foo', 'bar'],
            'b': 'baz',
github GoogleCloudPlatform / distributed-load-testing-using-kubernetes / docker-image / locust-tasks / tasks.py View on Github external
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import uuid

from datetime import datetime
from locust import HttpLocust, TaskSet, task


class MetricsTaskSet(TaskSet):
    _deviceid = None

    def on_start(self):
        self._deviceid = str(uuid.uuid4())

    @task(1)
    def login(self):
        self.client.post(
            '/login', {"deviceid": self._deviceid})

    @task(999)
    def post_metrics(self):
        self.client.post(
            "/metrics", {"deviceid": self._deviceid, "timestamp": datetime.now()})
github all-of-us / raw-data-repository / rdr_service / tools / load_test_locustfile.py View on Github external
link = history.get("link")
                if link and link[0]["relation"] == "next":
                    next_url = link[0]["url"]
                    absolute_path = True
                else:
                    next_url = None


class SignupUser(_AuthenticatedLocust):
    weight = 2
    # We estimate 100-1000 signups/day or 80-800s between signups (across all users).
    # Simulate 2 signups/s across a number of users for the load test.
    min_wait = weight * 500
    max_wait = min_wait

    class task_set(TaskSet):
        @task(1)
        def register_participant(self):
            self.locust.participant_generator.generate_participant(
                True, True  # include_physical_measurements
            )  # include_biobank_orders


class HealthProUser(_AuthenticatedLocust):
    """Queries run by HealthPro: look up user by name + dob or ID, and get summaries."""

    weight = 94
    # As of 2017 August, in 24h we see about 1000 ParticipantSummary and a similar number of
    # individual summary requests. Simulate more load than that (about 1M/day) to force resource
    # contention.
    min_wait = 1000
    max_wait = 10000
github all-of-us / raw-data-repository / rest-api / tools / load_test_locustfile.py View on Github external
history = self.client.request_json(next_url, absolute_path=absolute_path)
        link = history.get('link')
        if link and link[0]['relation'] == 'next':
          next_url = link[0]['url']
          absolute_path = True
        else:
          next_url = None


class SignupUser(_AuthenticatedLocust):
  weight = 2
  # We estimate 100-1000 signups/day or 80-800s between signups (across all users).
  # Simulate 2 signups/s across a number of users for the load test.
  min_wait = weight * 500
  max_wait = min_wait
  class task_set(TaskSet):
    @task(1)
    def register_participant(self):
      self.locust.participant_generator.generate_participant(
          True,  # include_physical_measurements
          True)  # include_biobank_orders


class HealthProUser(_AuthenticatedLocust):
  """Queries run by HealthPro: look up user by name + dob or ID, and get summaries."""
  weight = 94
  # As of 2017 August, in 24h we see about 1000 ParticipantSummary and a similar number of
  # individual summary requests. Simulate more load than that (about 1M/day) to force resource
  # contention.
  min_wait = 1000
  max_wait = 10000
github SvenskaSpel / locust-plugins / examples / pgreader.py View on Github external
#!/usr/bin/env python3
import os
from locust_plugins.postgresreader import PostgresReader
from locust import HttpLocust, task, TaskSet
from locust.wait_time import constant

customer_reader = PostgresReader(f"env='{os.environ['LOCUST_TEST_ENV']}' AND tb=0 AND lb=1")


class UserBehavior(TaskSet):
    @task
    def my_task(self):
        customer = customer_reader.get()
        self.client.get(f"/?ssn={customer['ssn']}")
        customer_reader.release(customer)


class MyHttpLocust(HttpLocust):
    task_set = UserBehavior
    wait_time = constant(0)
    host = "http://example.com"
github korymath / jann / locustfile.py View on Github external
headers = {
  "Accept": "application/json",
  "Content-Type": "application/json"
}

# Setting up a json data package for post request.
data = {
    "queryResult": {
      "queryText": "locust"
    }
  }


class UserBehavior(TaskSet):
    @task(1)
    def post_to_reply(self):
        self.client.post("/model_inference", json.dumps(data), headers=headers)


class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait = 5000
    max_wait = 9000
github locustio / locust / examples / nested_inline_tasksets.py View on Github external
from locust import HttpLocust, TaskSet, task, between


class WebsiteUser(HttpLocust):
    """
    Example of the ability of inline nested TaskSet classes
    """
    host = "http://127.0.0.1:8089"
    wait_time = between(2, 5)
    
    class task_set(TaskSet):
        @task
        class IndexTaskSet(TaskSet):
            @task(10)
            def index(self):
                self.client.get("/")
            
            @task(1)
            def stop(self):
                self.interrupt()
        
        @task
        def stats(self):
            self.client.get("/stats/requests")