Skip to content

Commit ce8e87d

Browse files
committed
update to functions load test
1 parent 174fb88 commit ce8e87d

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

tests/performance/locust_files/functions/workflow.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from tempfile import TemporaryDirectory
66
from typing import Annotated
77
from urllib.parse import quote
8-
from uuid import UUID
98

109
from locust import HttpUser, task
1110
from pydantic import BaseModel, Field
@@ -28,11 +27,12 @@ class UserSettings(BaseSettings):
2827
import numpy as np
2928
import pathlib as pl
3029
import json
30+
import os
3131
3232
def main():
3333
3434
input_json = pl.Path(os.environ["INPUT_FOLDER"]) / "function_inputs.json"
35-
object = json.load(input_json..read_text())
35+
object = json.loads(input_json.read_text())
3636
x = object["x"]
3737
y = object["y"]
3838
@@ -41,6 +41,7 @@ def main():
4141
4242
if __name__ == "__main__":
4343
main()
44+
4445
"""
4546

4647

@@ -88,23 +89,23 @@ def __init__(self, *args, **kwargs):
8889
self.pool_manager = PoolManager(retries=retry_strategy)
8990

9091
self._function_uid = None
91-
self._input_json_uuid = None
92-
self._script_uuid = None
92+
self._input_json = None
93+
self._script = None
9394
self._run_uid = None
9495
self._solver_job_uid = None
9596

9697
super().__init__(*args, **kwargs)
9798

9899
def on_stop(self) -> None:
99-
if self._script_uuid is not None:
100+
if self._script is not None:
100101
self.client.delete(
101-
f"/v0/files/{self._script_uuid}",
102+
f"/v0/files/{self._script.get('id')}",
102103
name="/v0/files/[file_id]",
103104
auth=self._auth,
104105
)
105-
if self._input_json_uuid is not None:
106+
if self._input_json is not None:
106107
self.client.delete(
107-
f"/v0/files/{self._input_json_uuid}",
108+
f"/v0/files/{self._input_json.get('id')}",
108109
name="/v0/files/[file_id]",
109110
auth=self._auth,
110111
)
@@ -126,17 +127,17 @@ def run_function(self):
126127
with TemporaryDirectory() as tmpdir_str, Path(tmpdir_str) as tmpdir:
127128
script = tmpdir / "script.py"
128129
script.write_text(_PYTHON_SCRIPT)
129-
self._script_uuid = self.upload_file(script)
130+
self._script = self.upload_file(script)
130131

131132
inputs = {"x": random.uniform(-10, 10), "y": random.uniform(-10, 10)}
132133
input_json = tmpdir / "function_inputs.json"
133134
input_json.write_text(json.dumps(inputs))
134-
self._input_json_uuid = self.upload_file(input_json)
135+
self._input_json = self.upload_file(input_json)
135136

136137
_function = Function(
137138
title="Test function",
138139
description="Test function",
139-
default_inputs={"input_0": f"{self._script_uuid}"},
140+
default_inputs={"input_1": json.dumps(self._script)},
140141
)
141142
response = self.client.post(
142143
"/v0/functions", json=_function.model_dump(), auth=self._auth
@@ -147,7 +148,7 @@ def run_function(self):
147148

148149
response = self.client.post(
149150
f"/v0/functions/{self._function_uid}:run",
150-
json={"input_1": f"{self._input_json_uuid}"},
151+
json={"input_2": json.dumps(self._input_json)},
151152
auth=self._auth,
152153
name="/v0/functions/[function_uid]:run",
153154
)
@@ -182,17 +183,16 @@ def wait_until_done(self):
182183
status = response.json().get("status")
183184
assert status in ["DONE", "FAILED"]
184185

185-
def upload_file(self, file: Path) -> UUID:
186+
def upload_file(self, file: Path) -> dict:
186187
assert file.is_file()
187188
with file.open(mode="rb") as f:
188189
files = {"file": f}
189190
response = self.client.put(
190191
"/v0/files/content", files=files, auth=self._auth
191192
)
192193
response.raise_for_status()
193-
file_uuid = response.json().get("id")
194-
assert file_uuid is not None
195-
return UUID(file_uuid)
194+
assert response.json().get("id") is not None
195+
return response.json()
196196

197197

198198
if __name__ == "__main__":

0 commit comments

Comments
 (0)