Custom Shaped Tests


Overview

LoadForge allows advanced users to create custom Load Shapes, which control how users scale up and down within a test. This is an advanced functionality and typically we advise using our default testing pattern.

Adding a Shape

To customize the shape of a test you need to add a class that uses the LoadTestShape parameter.

We will then automatically use that to determine the shape. Below is a snippet with a very custom shape profile.

import math
from locust import LoadTestShape

[.. test script here ..]

class DoubleWave(LoadTestShape):
    """
    A shape to immitate some specific user behaviour. In this example, midday
    and evening meal times. First peak of users appear at time_limit/3 and
    second peak appears at 2*time_limit/3
    Settings:
        min_users -- minimum users
        peak_one_users -- users in first peak
        peak_two_users -- users in second peak
        time_limit -- total length of test
    """

    min_users = 10
    peak_one_users = 50
    peak_two_users = 35
    time_limit = 180

    def tick(self):
        run_time = round(self.get_run_time())

        if run_time < self.time_limit:
            user_count = (
                (self.peak_one_users - self.min_users)
                * math.e ** -(((run_time / (self.time_limit / 10 * 2 / 3)) - 5) ** 2)
                + (self.peak_two_users - self.min_users)
                * math.e ** -(((run_time / (self.time_limit / 10 * 2 / 3)) - 10) ** 2)
                + self.min_users
            )
            return (round(user_count), round(user_count))
        else:
            return None

There are other examples in our Test Directory.