From 8b58f97aa288e953baa2dc5d6f6514849e7f16c3 Mon Sep 17 00:00:00 2001 From: Imbus Date: Tue, 10 Oct 2023 19:30:10 +0200 Subject: [PATCH] Stress testing python script --- server/testing/stresstest.py | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 server/testing/stresstest.py diff --git a/server/testing/stresstest.py b/server/testing/stresstest.py new file mode 100644 index 0000000..3773fd6 --- /dev/null +++ b/server/testing/stresstest.py @@ -0,0 +1,38 @@ +import requests +import multiprocessing +import time +import uuid + +# Target API endpoint +api_url = 'http://localhost:8080/api/register' + +# Send a POST request to the API with mock data +def send_request(_): + username = str(uuid.uuid4())[:8] + password = str(uuid.uuid4())[-12:] + payload = {'username': username, 'password': password, 'captcha': '1234'} + response = requests.post(api_url, json=payload) + return response.status_code + +# Number of parallel requests to send +num_requests = 10 + +# Pool of worker processes +pool = multiprocessing.Pool(processes=num_requests) + +# Record the start time +start_time = time.time() + +n = 0 +# Bench for one min +while time.time() - start_time < 60: + results = pool.map(send_request, range(num_requests)) + n += num_requests + +# Close the pool +pool.close() +pool.join() + +# Print summary +print(f'Total Requests: {n}') +print(f'Requests per second: {n / (time.time() - start_time)} (avg)') \ No newline at end of file