]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/test/test_stats.py
Simplify an existing test by using TimezoneMixin.
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_stats.py
1
2 from twisted.trial import unittest
3 from twisted.application import service
4 from allmydata.stats import CPUUsageMonitor
5 from allmydata.util import pollmixin
6 import allmydata.test.common_util as testutil
7
8 class FasterMonitor(CPUUsageMonitor):
9     POLL_INTERVAL = 0.1
10
11
12 class CPUUsage(unittest.TestCase, pollmixin.PollMixin, testutil.StallMixin):
13     def setUp(self):
14         self.s = service.MultiService()
15         self.s.startService()
16
17     def tearDown(self):
18         return self.s.stopService()
19
20     def test_monitor(self):
21         m = FasterMonitor()
22         s = m.get_stats() # before it has been started
23         self.failIf("cpu_monitor.1min_avg" in s)
24         m.setServiceParent(self.s)
25         def _poller():
26             return bool(len(m.samples) == m.HISTORY_LENGTH+1)
27         d = self.poll(_poller)
28         # pause one more second, to make sure that the history-trimming code
29         # is exercised
30         d.addCallback(self.stall, 1.0)
31         def _check(res):
32             s = m.get_stats()
33             self.failUnless("cpu_monitor.1min_avg" in s)
34             self.failUnless("cpu_monitor.5min_avg" in s)
35             self.failUnless("cpu_monitor.15min_avg" in s)
36             self.failUnless("cpu_monitor.total" in s)
37         d.addCallback(_check)
38         return d
39