Skip to content
Repos

TOSV

Python 2.2 KB69 lines Opens in site

Directory Raw Download

# Locust load flows for TOSV. Setup (boot, bootstrap, grant, seed
# blobs) is done by tests/load-run.sh, which exports creds plus blob
# IDs as env vars. Every task validates status plus body length, so
# wrong creds or corrupt crypto fail loudly instead of skewing stats.
import os
from locust import HttpUser, task, between

STORE = (os.environ["TOSV_STORE_USER"], os.environ["TOSV_STORE_PASS"])
FETCH = (os.environ["TOSV_FETCH_USER"], os.environ["TOSV_FETCH_PASS"])
BLOB = os.environ["TOSV_BLOB_ID"]
BLOB_LEN = int(os.environ["TOSV_BLOB_LEN"])
DAV_LEN = int(os.environ["TOSV_DAV_LEN"])
PAYLOAD_1M = os.urandom(1048576)


def _basic(user):
    import base64

    tok = base64.b64encode(f"{user[0]}:{user[1]}".encode()).decode()
    return {"Authorization": f"Basic {tok}"}


STORE_H = _basic(STORE)
FETCH_H = _basic(FETCH)


class VaultUser(HttpUser):
    wait_time = between(0.1, 1.0)

    @task(1)
    def store_1m(self):
        # 429 is the store rate cap (20 per 300s per peer) working as
        # designed; anything else outside 200 is a real failure.
        with self.client.post(
            "/store",
            data=PAYLOAD_1M,
            headers=STORE_H,
            name="/store 1MB",
            catch_response=True,
        ) as r:
            if r.status_code == 200 and r.json().get("id"):
                r.success()
            elif r.status_code == 429:
                r.success()
            else:
                r.failure(f"store: {r.status_code}")

    @task(3)
    def fetch_blob(self):
        with self.client.get(
            f"/fetch/{BLOB}",
            headers=FETCH_H,
            name="/fetch blob",
            catch_response=True,
        ) as r:
            if r.status_code == 200 and len(r.content) == BLOB_LEN:
                r.success()
            else:
                r.failure(f"fetch: {r.status_code} len={len(r.content)}")

    @task(1)
    def dav_get(self):
        with self.client.get(
            "/dav/load.bin", headers=FETCH_H, name="/dav GET", catch_response=True
        ) as r:
            if r.status_code == 200 and len(r.content) == DAV_LEN:
                r.success()
            else:
                r.failure(f"dav: {r.status_code} len={len(r.content)}")
43.2ms