-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.py
56 lines (49 loc) · 1.46 KB
/
monitor.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
"""
A worker which provides periodic monitoring and testing.
"""
import time
import random
import logging
# import our tester object
from integration.base import WebTest
# record events using python logging
log = logging.getLogger('seltest')
# set formatter to show line numbers
_formatter = logging.Formatter(
"[%(asctime)s] %(levelname)-7s " +
"(%(filename)s:%(lineno)3s) %(message)s",
"%Y-%m-%d %H:%M:%S")
# print log events to terminal
_handler = logging.StreamHandler()
_handler.setFormatter(_formatter)
log.addHandler(_handler)
log.setLevel(logging.DEBUG)
def integration_test(period, randomize=False):
"""
Will run an integration test every `period`.
Parameters
--------------
period: float, time to wait between tests
"""
while True:
# will open chromedriver
tester = WebTest()
with tester:
try:
tic = time.time()
tester.test_base()
except BaseException:
log.error('Integration test failed!',
exc_info=True)
continue
log.debug('Successfully tested in {:0.3f}'.format(
time.time() - tic))
if randomize:
current = random.random() * period
else:
current = period
log.debug(f'Sleeping for {current}s')
time.sleep(current)
if __name__ == "__main__":
# start the integration test
integration_test(period=100.0, randomize=True)