LocustIO - sgml/signature GitHub Wiki
URL Rate Limit Testing
Long Running JWT
'''
lr_jwt.py
'''
import jwt
import datetime
def long_running_jwt()
# Define a secret key
SECRET_KEY = "your_secret_key"
# Create a payload with a long expiration time
payload = {
"user": "locust_test_user",
"iat": datetime.datetime.utcnow(), # Issued at
"exp": datetime.datetime.utcnow() + datetime.timedelta(hours=6), # Expires in 6 hours
}
# Generate the token
token = jwt.encode(payload, SECRET_KEY, algorithm="HS256")
print(f"Generated JWT: {token}")
return token
URL Request/Response
from locust import HttpUser, task
from lr_jwt import long_running_jwt
# Replace with your generated JWT
JWT_TOKEN = long_running_jwt()
class LoadTestUser(HttpUser):
@task
def test_endpoint(self):
headers = {"Authorization": f"Bearer {JWT_TOKEN}"}
self.client.get("/your/api/endpoint", headers=headers)