-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallelhttp.py
47 lines (39 loc) · 1.34 KB
/
parallelhttp.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
import requests
from testsbase import testsbase
import threading
from queue import Queue
from time import sleep, time
class parallelhttp(testsbase):
def __init__(self, config):
super().__init__(config)
self.q = Queue()
def run(self, vh=None):
print("testing parallel")
test_list = [self.test1, self.test2]
return super().run(tests=test_list, vh=vh, testfile='index.html')
def worker(self):
try:
response = requests.get(self.url)
self.q.put((response.status_code == 200) and (self.check_byhash(response)))
except Exception as err:
print(err)
def parallel_clients(self, number_of_treads):
threads = []
for i in range(number_of_treads):
t = threading.Thread(target=self.worker)
threads.append(t)
t.start()
for t in threads:
t.join()
results = [self.q.get() for _ in range(number_of_treads)]
return all(results) and (len(results) == number_of_treads)
def test1(self):
""" 100 connections"""
start = time()
r = self.parallel_clients(100)
return r and (time() - start < 1)
def test2(self):
""" 500 connections """
start = time()
r = self.parallel_clients(500)
return r and (time() - start < 10)