feat(test): Add python script to simulate network traffic

Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
This commit is contained in:
Rodney Osodo
2024-07-10 22:39:57 +03:00
parent 5c03a1762f
commit 1e7006ee57
+42
View File
@@ -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()