Skip to content

Instantly share code, notes, and snippets.

@clarenceb
Created May 17, 2024 03:53
Show Gist options
  • Save clarenceb/368a3a77ed15b095dd74337c2199de17 to your computer and use it in GitHub Desktop.
Save clarenceb/368a3a77ed15b095dd74337c2199de17 to your computer and use it in GitHub Desktop.
Basic Locust load testing script
from locust import HttpUser, task, between
class UserBehavior(HttpUser):
"""
Represents the user behavior for load testing.
This class defines the tasks that the user will perform during the load testing.
It is functionally similar to the JMeter test plan (SampleApp.jmx), where the user performs a series of tasks to simulate real-world
"""
wait_time = between(0.1, 1) # Represents the wait time between consecutive tasks performed by the user.
@task
def lasttimestamp(self):
"""
Performs a GET request to retrieve the timestamp of the last visit to the site.
This method sends a GET request to the "/lasttimestamp" endpoint.
"""
self.client.get("/lasttimestamp")
@task
def add(self):
"""
Performs a POST request to increment the visitor counter by 1.
This method sends a POST request to the "/add" endpoint with data parameter set to "1".
"""
self.client.post("/add", data="1")
@task
def get(self):
"""
Performs a GET request to retrieve the current the visitor count.
This method sends a GET request to the "/get" endpoint.
"""
self.client.get("/get")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment