diff --git a/fixtures/100_kb.png b/fixtures/100_kb.png index 407be5cc50653075a540bdfdc33931531852b8df..da1dfb90e7c41de55aeb63d311937cdac9edd929 100644 Binary files a/fixtures/100_kb.png and b/fixtures/100_kb.png differ diff --git a/fixtures/10_mb.jpg b/fixtures/10_mb.jpg index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6c5d4031e03408e34ae476c5053ee497a91ac37b 100644 Binary files a/fixtures/10_mb.jpg and b/fixtures/10_mb.jpg differ diff --git a/fixtures/3_mb.jpg b/fixtures/3_mb.jpg index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b7f1f882873aaf18ecf6104b88fd1a7bfee58d7b 100644 Binary files a/fixtures/3_mb.jpg and b/fixtures/3_mb.jpg differ diff --git a/tests/load/README.md b/tests/load/README.md index 8e93be73f906efd15f8d7b784e30406b98af191c..25cdb2f9aca35889e957ec9e526486b2812ecef3 100644 --- a/tests/load/README.md +++ b/tests/load/README.md @@ -3,7 +3,7 @@ ## Installation ``` -pip install locustio +pip install locust ``` ## Running tests @@ -16,13 +16,11 @@ between DS container and swift. Select all tests from file, where HOST is host your document service(ex. `--host="http://0.0.0.0"` by default) ``` -locust -f test/load/locustfile.py --host=HOST +locust -f test/load/locustfile.py --host=HOST --filename=TEST_FIXTURE_FILE --authorization-token=AUTHORIZATION-TOKEN ``` - -Select specific tests - +Example Dev: ``` -locust -f tests/load/locustfile.py SomeTaskClass --host=HOST +locust -f tests/load/locustfile.py --host=http://localhost:8081 --filename=3_mb.jpg --authorization-token=auction_token ``` ### Open web-ui (default *:8089) and start new Locust swarm diff --git a/tests/load/locustfile.py b/tests/load/locustfile.py index cebbb0bc9d19647029de151441ef0ad29b20e709..a838515467be5a65bcb112a46b8b1bd4300da9f2 100644 --- a/tests/load/locustfile.py +++ b/tests/load/locustfile.py @@ -1,57 +1,37 @@ import jwt import requests -from locust import HttpUser, TaskSet, task, between +from locust import HttpUser, task, between, events + -_PUBLIC_KEY = None _ALGORITHM = 'RS256' DOC_ID = None FILE_CONTENT = None -def get_public_key(): - global _PUBLIC_KEY - if not _PUBLIC_KEY: - with open('secrets/ds-key.pub') as key_file: - _PUBLIC_KEY = key_file.read() - return _PUBLIC_KEY +def _decode_token(token): + return jwt.decode(token, algorithms=[_ALGORITHM], options={"verify_signature": False}) -def _decode_token(token): - return jwt.decode(token, get_public_key(), algorithms=[_ALGORITHM]) +@events.init_command_line_parser.add_listener +def _(parser): + parser.add_argument("--filename", type=str, default="10_mb.jpg", help="Test file name") + parser.add_argument("--authorization-token", type=str, default="my_auction_token", help="Authorization token") -class BaseDSFlow(TaskSet): +class BaseDSFlowTest(HttpUser): """ - TaskSet to test base DS api working flow + Task to test base DS api working flow """ - filename = "3_mb.jpg" - - def __init__(self, parent): - super(BaseDSFlow, self).__init__(parent) - if not DOC_ID: - self._load_file() - - def _load_file(self): - global DOC_ID - global FILE_CONTENT - path_to_file = f"fixtures/{self.filename}" - with open(path_to_file, 'rb') as f: - FILE_CONTENT = f.read() - response = requests.put( - f"{self.locust.host}/api/documents/public", - data={"documentType": "auctionProtocol"}, - files={"file": (self.filename, FILE_CONTENT, 'image/jpeg')} - ) - token = _decode_token(response.content) - DOC_ID = token['id'] + wait_time = between(1, 2) @task def upload_doc(self): self.client.put( "/api/documents/public", data={"documentType": "auctionProtocol"}, - files={"file": (self.filename, FILE_CONTENT, 'image/jpeg')}, + headers={"Authorization": self.environment.parsed_options.authorization_token}, + files={"file": (self.environment.parsed_options.filename, FILE_CONTENT, 'image/jpeg')}, ) @task @@ -60,7 +40,18 @@ class BaseDSFlow(TaskSet): f"/api/documents/public/{DOC_ID}" ) + def on_start(self): + global DOC_ID + global FILE_CONTENT + path_to_file = f"fixtures/{self.environment.parsed_options.filename}" + with open(path_to_file, 'rb') as f: + FILE_CONTENT = f.read() -class BaseDSFlowTest(HttpUser): - task_set = BaseDSFlow - wait_time = between(1, 2) + response = requests.put( + f"{self.host}/api/documents/public", + data={"documentType": "auctionProtocol"}, + headers={"Authorization": self.environment.parsed_options.authorization_token}, + files={"file": (self.environment.parsed_options.filename, FILE_CONTENT, 'image/jpeg')} + ) + token = _decode_token(response.content) + DOC_ID = token['id']