aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/unit/test_process_cache.py
blob: 508d14a42247d192bbf035b243d2218440a703c7 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This file is part of Buildbot.  Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

import mock
from twisted.trial import unittest
from buildbot.process import cache

class CacheManager(unittest.TestCase):

    def setUp(self):
        self.caches = cache.CacheManager()

    def make_config(self, **kwargs):
        cfg = mock.Mock()
        cfg.caches = kwargs
        return cfg

    def test_get_cache_idempotency(self):
        foo_cache = self.caches.get_cache("foo", None)
        bar_cache = self.caches.get_cache("bar", None)
        foo_cache2 = self.caches.get_cache("foo", None)
        self.assertIdentical(foo_cache, foo_cache2)
        self.assertNotIdentical(foo_cache, bar_cache)

    def test_reconfigService(self):
        # load config with one cache loaded and the other not
        foo_cache = self.caches.get_cache("foo", None)
        d = self.caches.reconfigService(
                self.make_config(foo=5, bar=6, bing=11))
        @d.addCallback
        def check(_):
            bar_cache = self.caches.get_cache("bar", None)
            self.assertEqual((foo_cache.max_size, bar_cache.max_size),
                            (5, 6))

    def test_get_metrics(self):
        self.caches.get_cache("foo", None)
        self.assertIn('foo', self.caches.get_metrics())
        metric = self.caches.get_metrics()['foo']
        for k in 'hits', 'refhits', 'misses', 'max_size':
            self.assertIn(k, metric)