From 58c46929bf5d64b7d16995da0554fa3f3da406b3 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Thu, 28 Dec 2023 05:02:56 +0800 Subject: [PATCH] Metadata endpoint load tests (#737) * Initial commit * WIP: No longer getting missing required header error - now getting a different error about multiple values being returned - still cannot find metadata file once written * Fixed indentation * header map with lowercase keys * Added test for header casing conversion to lowercase * Updated all calls to get headers to use lowercase name * Reverted all changes related to new PR 739 * Added flag to make sure the metadata endpoint is called only after the order endpoint has been called * Changed to generate submission_id per user and reduce the task weight for metadata endpoint calls * Moved orders_api_called flag instantiation --------- Co-authored-by: tjohnson7021 <86614374+tjohnson7021@users.noreply.github.com> Co-authored-by: jorge Lopez Co-authored-by: halprin Co-authored-by: Jorge Lopez <49923512+jorg3lopez@users.noreply.github.com> --- operations/locustfile.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/operations/locustfile.py b/operations/locustfile.py index cbb8576eb..60b335c63 100644 --- a/operations/locustfile.py +++ b/operations/locustfile.py @@ -1,4 +1,5 @@ import time +import uuid import logging import threading import urllib.parse @@ -11,6 +12,7 @@ AUTH_ENDPOINT = "/v1/auth/token" DEMOGRAPHICS_ENDPOINT = "/v1/etor/demographics" ORDERS_ENDPOINT = "/v1/etor/orders" +METADATA_ENDPOINT = "/v1/etor/metadata" demographics_request_body = None order_request_body = None @@ -28,6 +30,9 @@ class SampleUser(FastHttpUser): def on_start(self): self.authenticate() + self.submission_id = str(uuid.uuid4()) + self.orders_api_called = False + # Start the token refreshing thread threading.Thread( target=self.authenticate_periodically, args=(), daemon=True @@ -58,11 +63,24 @@ def post_v1_etor_demographics(self): @task(5) def post_v1_etor_orders(self): - self.client.post( + response = self.client.post( ORDERS_ENDPOINT, + headers={ + "Authorization": self.access_token, + "RecordId": self.submission_id, + }, data=order_request_body, - headers={"Authorization": self.access_token}, ) + if response.status_code == 200: + self.orders_api_called = True + + @task(2) + def get_v1_etor_metadata(self): + if self.orders_api_called: + self.client.get( + f"{METADATA_ENDPOINT}/{self.submission_id}", + headers={"Authorization": self.access_token}, + ) @events.test_start.add_listener