~ubuntu-branches/ubuntu/karmic/tahoe-lafs/karmic

« back to all changes in this revision

Viewing changes to src/allmydata/test/test_stats.py

  • Committer: Bazaar Package Importer
  • Author(s): Zooko O'Whielacronx (Hacker)
  • Date: 2009-09-24 00:00:05 UTC
  • Revision ID: james.westby@ubuntu.com-20090924000005-ixe2n4yngmk49ysz
Tags: upstream-1.5.0
ImportĀ upstreamĀ versionĀ 1.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 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