-
Notifications
You must be signed in to change notification settings - Fork 307
/
Copy pathPyRequestsLibTest.py
49 lines (35 loc) · 1.22 KB
/
PyRequestsLibTest.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
import sys
import time
import requests
import concurrent.futures
import TestUtils
import TestKey
def load_url(url, session):
print("Loading URL...")
response = session.get(url)
global gBytesDownloaded
gBytesDownloaded += len(response.text);
print(response.status_code)
if __name__ == "__main__":
global gBytesDownloaded
gBytesDownloaded = 0
sessionString = TestKey.SessionKey
urlArray = TestUtils.buildUrlArray(sessionString)
session = requests.Session()
session.headers.update(TestUtils.UnrealStyleHeaders)
startMark = time.time()
out = []
CONNECTIONS = 100
with concurrent.futures.ThreadPoolExecutor(max_workers=CONNECTIONS) as executor:
future_to_url = (executor.submit(load_url, url, session) for url in urlArray)
for future in concurrent.futures.as_completed(future_to_url):
try:
data = future.result()
except Exception as exc:
data = str(type(exc))
print("Exception caught: " + data)
finally:
print("request completed")
out.append(data)
secsElapsed = time.time()-startMark
TestUtils.printSummary(secsElapsed, gBytesDownloaded)