From 1e7006ee570e3ef5a52df0a55bae24c8a2e91b03 Mon Sep 17 00:00:00 2001 From: Rodney Osodo Date: Wed, 10 Jul 2024 22:39:57 +0300 Subject: [PATCH] feat(test): Add python script to simulate network traffic Signed-off-by: Rodney Osodo --- test.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..17d5450 --- /dev/null +++ b/test.py @@ -0,0 +1,42 @@ +import requests +import time +import threading +import random + +BASE_URL = 'http://192.168.100.202:30081' # Replace with your actual URL + +ENDPOINTS = [ + '/hello', + '/goodbye', + '/login', + '/logout', + '/register', + '/users', + '/products', + '/orders', + '/cart', + '/checkout' +] + +def simulate_traffic(): + while True: + endpoint = random.choice(ENDPOINTS) + url = BASE_URL + endpoint + try: + response = requests.get(url) + print(f"Request to {endpoint} - Status code: {response.status_code}") + except requests.RequestException as e: + print(f"Request to {endpoint} failed: {str(e)}") + + time.sleep(random.uniform(0.1, 0.5)) + +NUM_THREADS = len(ENDPOINTS) +threads = [] + +for _ in range(NUM_THREADS): + thread = threading.Thread(target=simulate_traffic) + threads.append(thread) + thread.start() + +for thread in threads: + thread.join()