예제 #1
0
class TestExpirePlugin(TestCase, RegexFixer):
    def setUp(self):
        self.plugin = ExpireMonitor()
        self.plugin.redis_conn = MagicMock()
        self.plugin.logger = MagicMock()

    def test_stop_regex(self):
        regex = self.fix_re(self.plugin.regex)
        self.assertEquals(re.findall(regex, "timeout:blah1:blah2:bla3"), ["timeout:blah1:blah2:bla3"])
        self.assertEquals(re.findall(regex, "timeout:blah1:blah2"), [])

    def test_expire_monitor_time(self):
        # if the stop monitor passes then this is just testing whether
        # the handler acts on the key only if it has expired
        self.plugin._purge_crawl = MagicMock(side_effect=Exception("throw once"))

        self.plugin._get_current_time = MagicMock(return_value=5)

        # not timed out
        if self.plugin.check_precondition("key:stuff:blah:blah", 6):
            self.plugin.handle("key:stuff:blah:blah", 6)

        # timed out
        try:
            if self.plugin.check_precondition("key:stuff:blah:blah", 4):
                self.plugin.handle("key:stuff:blah:blah", 4)
            self.fail("Expire not called")
        except BaseException as e:
            self.assertEquals("throw once", e.message)
예제 #2
0
class TestExpirePlugin(TestCase, RegexFixer):
    def setUp(self):
        self.plugin = ExpireMonitor()
        self.plugin.redis_conn = MagicMock()
        self.plugin.logger = MagicMock()

    def test_stop_regex(self):
        regex = self.fix_re(self.plugin.regex)
        self.assertEquals(re.findall(regex, 'timeout:blah1:blah2:bla3'),
                          ['timeout:blah1:blah2:bla3'])
        self.assertEquals(re.findall(regex, 'timeout:blah1:blah2'), [])

    def test_expire_monitor_time(self):
        # if the stop monitor passes then this is just testing whether
        # the handler acts on the key only if it has expired
        self.plugin._purge_crawl = MagicMock(side_effect=Exception(
                                             "throw once"))

        self.plugin._get_current_time = MagicMock(return_value=5)

        # not timed out
        if self.plugin.check_precondition("key:stuff:blah:blah", 6):
            self.plugin.handle("key:stuff:blah:blah", 6)

        # timed out
        try:
            if self.plugin.check_precondition("key:stuff:blah:blah", 4):
                self.plugin.handle("key:stuff:blah:blah", 4)
            self.fail("Expire not called")
        except BaseException as e:
            self.assertEquals("throw once", e.message)
예제 #3
0
 def setUp(self):
     self.plugin = ExpireMonitor()
     self.plugin.redis_conn = MagicMock()
     self.plugin.logger = MagicMock()
예제 #4
0
 def setUp(self):
     self.plugin = ExpireMonitor()
     self.plugin.redis_conn = MagicMock()
     self.plugin.logger = MagicMock()