-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
65 lines (50 loc) · 1.9 KB
/
tests.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
57
58
59
60
61
62
63
64
65
import requests
import time
import csv
import pandas as pd
import matplotlib.pyplot as plt
# https://ca-central-1.console.aws.amazon.com/elasticbeanstalk/home?region=ca-central-1#/environment/dashboard?environmentId=e-akttpetemi
# http://ece444-pra5-try2.ca-central-1.elasticbeanstalk.com/
# sends the test cases to the api, and records the result & the latency.
def api_call(url, test):
start = time.time()
result = requests.post(url, test)
end = time.time()
latency = end - start
return result.status_code, latency
def boxplot():
df = pd.read_csv("test_results.csv")
plt.figure(figsize=(10, 6))
df.boxplot(column="Latency (s)", by="Test Nr", grid=False)
plt.title("Latency by Test Nr")
plt.suptitle("")
plt.xlabel("Test Nr")
plt.ylabel("Latency (s)")
plt.savefig("latency_boxplot.png")
print("Boxplot saved to 'latency_boxplot.png'.")
# Show the plot
plt.show()
return
def test():
url = "http://e444pra-5-env.eba-pkb2wvr5.us-east-2.elasticbeanstalk.com"
test_text = ["Donald Trump won the 2024 Election", # False
"Toronto is the Capital of Ontario", # True
"The USSR exists today", # False
"Christmas is celebrated in december"] # True
test_results = []
print("starting api calls")
for i in range(100):
for num, text in enumerate(test_text):
print(num, text)
status_code, latency = api_call(url, text)
test_results.append([num, text, latency])
print("finished api calls")
print("starting writing results to csv")
with open("test_results.csv", "w", newline='') as f:
writer = csv.writer(f)
writer.writerow(["Test Nr", "Article", "Latency (s)"])
writer.writerows(test_results)
print("finished writing results to csv")
boxplot()
if __name__ == "__main__":
test()