allow the correct number of samples in

also speed up the test with some shorter intervals
This commit is contained in:
Jean-Paul Calderone 2022-03-18 12:36:48 -04:00
parent e17f4e6804
commit 98634ae5cb
2 changed files with 5 additions and 5 deletions

View File

@ -21,7 +21,7 @@ class CPUUsageMonitor(service.MultiService):
def __init__(self):
service.MultiService.__init__(self)
self.samples: list[tuple[float, float]] = deque([], self.HISTORY_LENGTH)
self.samples: list[tuple[float, float]] = deque([], self.HISTORY_LENGTH + 1)
# we provide 1min, 5min, and 15min moving averages
TimerService(self.POLL_INTERVAL, self.check).setServiceParent(self)

View File

@ -17,7 +17,7 @@ from allmydata.util import pollmixin
import allmydata.test.common_util as testutil
class FasterMonitor(CPUUsageMonitor):
POLL_INTERVAL = 0.1
POLL_INTERVAL = 0.01
class CPUUsage(unittest.TestCase, pollmixin.PollMixin, testutil.StallMixin):
@ -36,9 +36,9 @@ class CPUUsage(unittest.TestCase, pollmixin.PollMixin, testutil.StallMixin):
def _poller():
return bool(len(m.samples) == m.HISTORY_LENGTH+1)
d = self.poll(_poller)
# pause one more second, to make sure that the history-trimming code
# is exercised
d.addCallback(self.stall, 1.0)
# pause a couple more intervals, to make sure that the history-trimming
# code is exercised
d.addCallback(self.stall, FasterMonitor.POLL_INTERVAL * 2)
def _check(res):
s = m.get_stats()
self.failUnless("cpu_monitor.1min_avg" in s)