-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_httpress.py
More file actions
executable file
·53 lines (45 loc) · 1.19 KB
/
test_httpress.py
File metadata and controls
executable file
·53 lines (45 loc) · 1.19 KB
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
#!/usr/bin/python
import unittest
import subprocess
import inspect
import re
txt_red = "\033[1;31m"
txt_green = "\033[1;32m"
txt_color_off ="\033[0;0m"
def exe(command):
try:
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, _ = p.communicate()
except:
print ("Error occured during command execution")
print ("Command: {0}".format(" ".join(command)))
raise
else:
return out
def print_failed():
print ("%s\t" + txt_red + "[FAILED]" + txt_color_off)\
% inspect.stack()[1][3]
def print_success():
print ("%s\t" + txt_green + "[SUCCESS]" + txt_color_off)\
% inspect.stack()[1][3]
class TestMethods(unittest.TestCase):
def test_single_url(self):
try:
command = ["/home/denis/tests/atomic/bin/lin64/httpress",\
"-t", "10", "http://10.30.17.179/index1.html"]
output = exe(command)
self.assertTrue("URL#000 |" in output)
print_success()
print(output)
test_result = re.search("\{\s[0-9]+\.[0-9]+\s\}", output)
res = test_result.group()
rate = float(res[2:-2])
if rate == 0:
raise Exception("Rate: 0 looks suspicious!")
print(rate)
except Exception:
print_failed()
if __name__ == '__main__':
unittest.main()