forked from antonengelhardt/wasm-oidc-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
56 lines (48 loc) · 1.76 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import csv
import requests
import threading
import time
import sys
from datetime import datetime
# Function for making requests
def make_request(thread_id, cookie):
headers = {'Cookie': f'oidcSession={cookie}'}
for i in range(100):
start_time = datetime.now()
try:
response = requests.get('http://localhost:10000', headers=headers)
end_time = datetime.now()
duration = (end_time - start_time).total_seconds() * 1000 # convert to milliseconds
with lock:
writer.writerow([start_time, end_time, duration, response.status_code])
except Exception as e:
end_time = datetime.now()
duration = (end_time - start_time).total_seconds() * 1000 # convert to milliseconds
with lock:
writer.writerow([start_time, end_time, duration, 'ERROR', str(e)])
# Sleep for 0.1 second to avoid overloading the server
time.sleep(0.1)
# Check command line arguments
if len(sys.argv) != 2:
print("Usage: python main.py <cookie-value>")
sys.exit(1)
# Get the cookie value from command line arguments
cookie = sys.argv[1]
# Create the csv writer
filename = 'results-' + datetime.now().strftime('%Y-%m-%d-%H-%M-%S') + '.csv'
file = open(filename, 'w', newline='')
writer = csv.writer(file)
writer.writerow(["start_time", "end_time", "duration_ms", "status_code"])
# Define a lock object to ensure that threads write to the file one at a time
lock = threading.Lock()
# Create and start 10 threads
threads = []
for i in range(10):
thread = threading.Thread(target=make_request, args=(i, cookie,))
thread.start()
threads.append(thread)
# Wait for all threads to finish
for thread in threads:
thread.join()
# Close the file
file.close()