Example tests and snippets
Checking Response Text and Times
LoadForge will typically consider any valid HTTP code response a success. However, you can require a certain string, response code, or even time in your test.
Below we can see a snippet that checks for the word "Success" in a response, and then generates a failure if its taken more than half a second to reply.
This is useful as it shows an example of monitoring the actual timings around a response. With LoadForge you can parse the content that comes back, read headers, monitor timings and more.
This test will report failures in your LoadForge test when anything is slow.
Code example
import time
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(3, 5)
@task(1)
def index_page(self):
with self.client.get("/", catch_response=True) as response:
if response.text != "Success":
response.failure("Got wrong response")
elif response.elapsed.total_seconds() > 0.5:
response.failure("Request took too long")
Alternatives
You can also set a timeout on your client requests, as shown in the test example below. Note that timeout is always in seconds.
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(5, 9)
@task(1)
def index_page(self):
self.client.get('/page1', timeout=10)
self.client.get('/page2', timeout=5)
Locust Test Example
LoadForge is powered by locust, meaning open source locust users can copy this script as well. If you are a locust user, consider importing your script to LoadForge to supercharge your testing!