-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from EURODEO/load-test
Fix and move local locust loadtest, and add EWC loadtest code to repo
- Loading branch information
Showing
4 changed files
with
136 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from datetime import datetime, timedelta, UTC | ||
import random | ||
|
||
from locust import HttpUser | ||
from locust import task | ||
|
||
headers = {"Accept-Encoding": "br"} | ||
|
||
common_standard_names = [ | ||
"wind_speed", | ||
"wind_from_direction", | ||
"air_temperature", | ||
] | ||
|
||
polygon_size = [0.5, 1.0, 2.0, 4.0] | ||
hours_choice = [1, 3, 6, 12, 24] | ||
|
||
|
||
class ESohUser(HttpUser): | ||
def on_start(self): | ||
response = self.client.get("/collections/observations/locations", headers=headers) | ||
stations = response.json()["features"] | ||
self.stations = {s["id"]: s["properties"]["parameter-name"] for s in stations} | ||
self.station_ids = list(self.stations.keys()) | ||
self.stations_by_location = { | ||
(s["geometry"]["coordinates"][0], s["geometry"]["coordinates"][1]): s["properties"]["parameter-name"] | ||
for s in stations | ||
} | ||
self.station_locations = list(self.stations_by_location.keys()) | ||
|
||
# @task | ||
# def get_data_single_station_single_parameter(self): | ||
# station_id = random.choice(self.station_ids) | ||
# parameter = random.choice(self.stations[station_id]) | ||
# response = self.client.get( | ||
# f"/collections/observations/locations/{station_id}?parameter-name={parameter}", | ||
# name="location", | ||
# headers=headers | ||
# ) | ||
|
||
@task | ||
def get_data_single_station_single_parameter_last_x_hours(self): | ||
hours = random.choice(hours_choice) | ||
date_time = datetime.now(UTC) - timedelta(hours=hours) | ||
dt_string = date_time.strftime("%Y-%m-%dT%H:%M:%SZ") | ||
station_id = random.choice(self.station_ids) | ||
parameter = random.choice(self.stations[station_id]) | ||
self.client.get( | ||
f"/collections/observations/locations/{station_id}?parameter-name={parameter}&datetime={dt_string}/..", | ||
name=f"location {hours:02d} hours", | ||
headers=headers, | ||
) | ||
|
||
@task | ||
def get_data_single_position_single_parameter(self): | ||
(lon, lat) = random.choice(self.station_locations) | ||
parameter = random.choice(self.stations_by_location[(lon, lat)]) | ||
self.client.get( | ||
f"/collections/observations/position?coords=POINT({lon} {lat})¶meter-name={parameter}", | ||
name="position", | ||
headers=headers, | ||
) | ||
|
||
@task | ||
def get_data_area_single_parameter_last_hour(self): | ||
date_time = datetime.now(UTC) - timedelta(hours=1) | ||
dt_string = date_time.strftime("%Y-%m-%dT%H:%M:%SZ") | ||
standard_name = random.choice(common_standard_names) | ||
(cx, cy) = random.choice(self.station_locations) | ||
sz = random.choice(polygon_size) / 2.0 | ||
left = cx - sz | ||
bottom = cy - sz | ||
right = cx + sz | ||
top = cy + sz | ||
polygon = f"POLYGON(({left} {bottom},{right} {bottom},{right} {top},{left} {top},{left} {bottom}))" | ||
url = f"/collections/observations/area?coords={polygon}&standard_names={standard_name}&datetime={dt_string}/.." | ||
self.client.get(url, name=f"area {sz*2.0}deg x {sz*2.0}deg x 1h", headers=headers) | ||
# if sz == 2.0: | ||
# j = response.json() | ||
# # print(sz*2.0) | ||
# if response.status_code != 200: | ||
# print(0) | ||
# elif j["type"] == "CoverageCollection": | ||
# print(len(j["coverages"])) | ||
# else: | ||
# print(1) | ||
# # print(j) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import random | ||
|
||
from locust import HttpUser | ||
from locust import task | ||
|
||
parameters = [ | ||
"wind_speed:10.0:mean:PT10M", | ||
"wind_speed:10.0:mean:PT10M", | ||
"relative_humidity:2.0:mean:PT1M", | ||
"air_temperature:2.0:mean:PT1M", | ||
] | ||
# fmt: off | ||
stations = [ | ||
"0-20000-0-06203", "0-20000-0-06204", "0-20000-0-06205", "0-20000-0-06207", "0-20000-0-06208", "0-20000-0-06211", | ||
"0-20000-0-06214", "0-20000-0-06215", "0-20000-0-06235", "0-20000-0-06239", "0-20000-0-06242", "0-20000-0-06251", | ||
"0-20000-0-06260", "0-20000-0-06269", "0-20000-0-06270", "0-20000-0-06275", "0-20000-0-06279", "0-20000-0-06280", | ||
"0-20000-0-06290", "0-20000-0-06310", "0-20000-0-06317", "0-20000-0-06319", "0-20000-0-06323", "0-20000-0-06330", | ||
"0-20000-0-06340", "0-20000-0-06344", "0-20000-0-06348", "0-20000-0-06350", "0-20000-0-06356", "0-20000-0-06370", | ||
"0-20000-0-06375", "0-20000-0-06380", | ||
] | ||
# fmt: on | ||
headers = {"Accept-Encoding": "br"} | ||
|
||
|
||
class WebsiteUser(HttpUser): | ||
@task | ||
def get_data_single_station_single_parameter(self): | ||
parameter = random.choice(parameters) | ||
station_id = random.choice(stations) | ||
response = self.client.get( | ||
f"/collections/observations/locations/{station_id}?parameter-name={parameter}", | ||
name=f"single station {parameter}", | ||
headers=headers, | ||
) | ||
if response.status_code != 200: | ||
print(station_id, parameter) | ||
|
||
@task | ||
def get_data_bbox_three_parameters(self): | ||
self.client.get( | ||
"/collections/observations/area?parameter-name=" | ||
"wind_speed:10.0:mean:PT10M,wind_speed:10.0:mean:PT10M,relative_humidity:2.0:mean:PT1M&" | ||
"coords=POLYGON((5.0 52.0,6.0 52.0,6.0 52.1,5.0 52.1,5.0 52.0))", | ||
name="bbox", | ||
headers=headers, | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[run] | ||
omit = test/* | ||
omit = | ||
test/* | ||
load-test/* |
2cbcf24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit Test Coverage Report