source: trunk/src/allmydata/test/test_stats.py

Last change on this file was 1cfe843d, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-22T23:40:25Z

more python2 removal

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"""
2Ported to Python 3.
3"""
4
5from twisted.trial import unittest
6from twisted.application import service
7from allmydata.stats import CPUUsageMonitor
8from allmydata.util import pollmixin
9import allmydata.test.common_util as testutil
10
11class FasterMonitor(CPUUsageMonitor):
12    POLL_INTERVAL = 0.01
13
14
15class CPUUsage(unittest.TestCase, pollmixin.PollMixin, testutil.StallMixin):
16    def setUp(self):
17        self.s = service.MultiService()
18        self.s.startService()
19
20    def tearDown(self):
21        return self.s.stopService()
22
23    def test_monitor(self):
24        m = FasterMonitor()
25        s = m.get_stats() # before it has been started
26        self.failIf("cpu_monitor.1min_avg" in s)
27        m.setServiceParent(self.s)
28        def _poller():
29            return bool(len(m.samples) == m.HISTORY_LENGTH+1)
30        d = self.poll(_poller)
31        # pause a couple more intervals, to make sure that the history-trimming
32        # code is exercised
33        d.addCallback(self.stall, FasterMonitor.POLL_INTERVAL * 2)
34        def _check(res):
35            s = m.get_stats()
36            self.failUnless("cpu_monitor.1min_avg" in s)
37            self.failUnless("cpu_monitor.5min_avg" in s)
38            self.failUnless("cpu_monitor.15min_avg" in s)
39            self.failUnless("cpu_monitor.total" in s)
40        d.addCallback(_check)
41        return d
42
Note: See TracBrowser for help on using the repository browser.