|
| 1 | +""" |
| 2 | +Run locally: |
| 3 | + pip install -r requirements.txt |
| 4 | + locust -f locust.py --headless -u 50 -r 5 --run-time 2m --host http://localhost:8000 |
| 5 | +""" |
| 6 | + |
| 7 | +import logging |
| 8 | +from locust import HttpUser, task, between |
| 9 | +from locust.exception import StopUser |
| 10 | +from tests.performance.auth import get_token_client_credentials |
| 11 | +from tests.performance.utils import random_temporal_extent |
| 12 | + |
| 13 | + |
| 14 | +class DispatchUser(HttpUser): |
| 15 | + |
| 16 | + logger = logging.getLogger("user") |
| 17 | + wait_time = between(1.0, 3.0) # user "think" time |
| 18 | + |
| 19 | + def on_start(self): |
| 20 | + token = get_token_client_credentials() |
| 21 | + self.headers = { |
| 22 | + "Authorization": f"Bearer {token}", |
| 23 | + "Content-Type": "application/json", |
| 24 | + } |
| 25 | + |
| 26 | + # simple health check at start; stop user if service unreachable |
| 27 | + with self.client.get("/health", name="health", catch_response=True) as r: |
| 28 | + if r.status_code != 200: |
| 29 | + r.failure(f"Health check failed: {r.status_code}") |
| 30 | + # stop this virtual user if service down |
| 31 | + raise StopUser() |
| 32 | + |
| 33 | + @task |
| 34 | + def execute_statistics(self): |
| 35 | + extent = random_temporal_extent(2024) |
| 36 | + payload = { |
| 37 | + "title": "Test Processing Job", |
| 38 | + "label": "openeo", |
| 39 | + "service": { |
| 40 | + "endpoint": "https://openeo.vito.be", |
| 41 | + "application": "https://openeo.vito.be/openeo/1.2/processes/u:ff5c137fbbbf409d14a99875b97109874058056a9a02193e6fde8217d2f1f3e8@egi.eu/timeseries_graph", |
| 42 | + }, |
| 43 | + "format": "json", |
| 44 | + "parameters": { |
| 45 | + "spatial_extent": { |
| 46 | + "type": "Point", |
| 47 | + "coordinates": [5.196363779293476, 51.25007554845948], |
| 48 | + }, |
| 49 | + "collection": "CGLS_NDVI300_V2_GLOBAL", |
| 50 | + "band": "NDVI", |
| 51 | + "temporal_extent": extent, |
| 52 | + }, |
| 53 | + } |
| 54 | + self.logger.info(f"Requesting statistics for extent: {extent}") |
| 55 | + self.client.post( |
| 56 | + "/sync_jobs", |
| 57 | + json=payload, |
| 58 | + name="statistics", |
| 59 | + timeout=30, |
| 60 | + headers=self.headers, |
| 61 | + ) |
0 commit comments