From b6fa053291f16f5debef3d5358443aeb5deacc66 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 1 Sep 2023 17:21:26 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(locustfile.py):=20update=20h?= =?UTF-8?q?ost=20URL=20to=20include=20correct=20port=20number=20=E2=9C=A8?= =?UTF-8?q?=20feat(locustfile.py):=20add=20x-api-key=20header=20to=20reque?= =?UTF-8?q?sts=20for=20authentication=20=F0=9F=90=9B=20fix(locustfile.py):?= =?UTF-8?q?=20provide=20default=20value=20for=20FLOW=5FID=20environment=20?= =?UTF-8?q?variable=20to=20prevent=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/locust/locustfile.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/locust/locustfile.py b/tests/locust/locustfile.py index b3e6b58b0..765637a61 100644 --- a/tests/locust/locustfile.py +++ b/tests/locust/locustfile.py @@ -6,18 +6,24 @@ import os class NameTest(FastHttpUser): - host = "http://localhost/api/v1" # make sure the port number is correct + host = "http://localhost:7860/api/v1" # make sure the port number is correct wait_time = between(1, 5) with open("names.txt", "r") as file: names = [line.strip() for line in file.readlines()] + headers = { + # api-key + "x-api-key": "lf-a1EsRC75ybWiKRCRLyhX1R9rPlqQKYlnRQoZWysg6NM", + } + def poll_task(self, task_id, sleep_time=1): while True: with self.rest( "GET", f"/task/{task_id}/status", name="task_status", + headers=self.headers, ) as response: status = response.js.get("status") if status == "SUCCESS": @@ -29,14 +35,18 @@ class NameTest(FastHttpUser): @task def send_name_and_check(self): name = random.choice(self.names) - flow_id = os.getenv("FLOW_ID") + flow_id = os.getenv("FLOW_ID", "88989f6d-8da4-4d6f-8205-480693c36200") session_id = f"{name}-{time.time()}" def process(flow_id, payload): task_id = None print(f"Processing {payload}") with self.rest( - "POST", f"/process/{flow_id}", json=payload, name="process" + "POST", + f"/process/{flow_id}", + json=payload, + name="process", + headers=self.headers, ) as response: if response.status_code != 200: response.failure("Process call failed")