-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_restart_monitor.py
33 lines (26 loc) · 1019 Bytes
/
test_restart_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
from ismain import is_main
import time
import random
from pyship.launcher import RestartMonitor
def test_restart_monitor_excessive():
restart_monitor = RestartMonitor()
for _ in range(0, restart_monitor.max_samples):
assert not restart_monitor.excessive()
restart_monitor.add()
time.sleep(0.1 * random.random())
for _ in range(0, 4):
assert restart_monitor.excessive()
restart_monitor.add()
time.sleep(0.1 * random.random())
def test_restart_monitor_not_excessive():
restart_monitor = RestartMonitor()
quick = 0.1
restart_monitor.quick = quick # make the "quick" time short to test that we never go below that
# run for a lot more than max samples
for _ in range(0, 2 * restart_monitor.max_samples):
assert not restart_monitor.excessive()
restart_monitor.add()
time.sleep(quick + 0.1) # always longer than "quick"
if is_main():
test_restart_monitor_excessive()
test_restart_monitor_not_excessive()