<- Test Directory

Adding Sleeps

How to add custom sleep times to a test


By default, you should set your wait_time to handle "user timings" like reading the page, etc. However, you can have custom sleeps anywhere in the test should you need to.

The test below is wait for between 10 and 20 seconds for each task a client executes, but the task to load_page will also sleep between 10 and 60 seconds between its two get requests.


import random
from random import randint
from locust import HttpUser, TaskSet, task, between
import time

class AwesomeUser(HttpUser):
    wait_time = between(10, 20)
    def load_page(self):        
        # Sleep for 10 - 60 seconds
        time.sleep(random.randint(10, 60))

This guide is part of the LoadForge Directory, an index of locustfile's for use with LoadForge website and API load tests. We also provide a wizard to generate tests, and onboarding assistance for clients. Contact us should you have any questions.

LoadForge provides load testing and stress tests for websites, APIs and servers. It uses your cloud account to rapidly scale large numbers of simulated users to load test your website, store, API, or application for cheap - just cents per test!

For more help on Tests please see our official documentation. Logged in users can also use our wizard to generate a locustfile, or you can record your browser steps.

Ready to run your test?
Start your first test within minutes.