Skip to content

Instantly share code, notes, and snippets.

@anandtripathi5
Last active April 1, 2022 12:39
Show Gist options
  • Save anandtripathi5/f7f25114d42ea24e4ae200ee20e1599e to your computer and use it in GitHub Desktop.
Save anandtripathi5/f7f25114d42ea24e4ae200ee20e1599e to your computer and use it in GitHub Desktop.
from locust import HttpUser, task, between
from random import randint
class AwesomeApplication(HttpUser):
wait_time = between(1, 5)
@task
def hello(self):
self.client.get("/hello")
@task(3)
def world(self):
self.client.get("/world")
@task
def square(self):
self.client.get(f"/square/{randint(0, 100)}", headers={"Authorization": f'Bearer {self.token}'})
def on_start(self):
# Here you can specify your code that you want to run before running the actual
# test cases
response = self.client.post("/login", json={"username": "test", "password": "test"})
self.token = response.json()['access_token']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment