Testing Requests based SDKsΒΆ

If a prebuilt SDK is available for your target system. Locust has a supported pattern for integrating its usage into your load testing efforts.

The only perquisite to achieve this; is that the SDK needs to have an accessible request.Sessions class.

The following example shows the locust client overwriting the internal _session object of Archivist SDK during startup.

import locust
from locust.user import task
from archivist.archivist import Archivist  # Example SDK under test

class ArchivistUser(locust.HttpUser):
    def on_start(self):
        AUTH_TOKEN = None

        with open("auth.text") as f:
            AUTH_TOKEN = f.read()

        # Start an instance of of the SDK
        self.arch: Archivist = Archivist(url=self.host, auth=AUTH_TOKEN)
        # overwrite the internal _session attribute with the locust session
        self.arch._session = self.client

    def Create_assets(self):
        """User creates assets as fast as possible"""

        while True:
            self.arch.assets.create(behaviours=["Builtin", "RecordEvidence", "Attachments"], attrs={"foo": "bar"})