コード例 #1
0
 def test_sweep_and_clean_cache_schedules_again(self):
     """
     Sweep and clean should schedule a new sweep and clean in
     clean_interval seconds.
     """
     event_loop = mock.MagicMock()
     connector = HttpConnector(event_loop)
     event_loop.call_later = mock.MagicMock()
     connector._sweep_and_clean_cache(event_loop, 300)
     sweep = connector._sweep_and_clean_cache
     event_loop.call_later.assert_called_once_with(300, sweep, event_loop,
                                                   300)
コード例 #2
0
 def test_sweep_and_clean_cache_stale_items_only(self):
     """
     If the lookup cache is only full of stale items then the cache should
     be emtied.
     """
     event_loop = mock.MagicMock()
     connector = HttpConnector(event_loop)
     event_loop.call_later = mock.MagicMock()
     now = time.time()
     for i in range(10):
         connector.lookups[str(i)] = {
             'last_access': now - 500,
             'lookup': mock.MagicMock()
         }
     connector._sweep_and_clean_cache(event_loop, 300)
     self.assertEqual(len(connector.lookups), 0)
コード例 #3
0
 def test_sweep_and_clean_cache_fresh_items_only(self):
     """
     If the lookup cache is only full of fresh items then the cache remains
     the same (nothing to delete).
     """
     event_loop = mock.MagicMock()
     connector = HttpConnector(event_loop)
     event_loop.call_later = mock.MagicMock()
     now = time.time()
     for i in range(10):
         connector.lookups[str(i)] = {
             'last_access': now,
             'lookup': mock.MagicMock()
         }
     connector._sweep_and_clean_cache(event_loop, 300)
     self.assertEqual(len(connector.lookups), 10)
コード例 #4
0
 def test_sweep_and_clean_cache_mixed_fresh_and_stale_items(self):
     """
     Only the stale items should be removed from the cache.
     """
     event_loop = mock.MagicMock()
     connector = HttpConnector(event_loop)
     event_loop.call_later = mock.MagicMock()
     now = time.time()
     for i in range(10):
         if i % 2:
             access = now - 500
         else:
             access = now
         connector.lookups[str(i)] = {
             'last_access': access,
             'lookup': mock.MagicMock()
         }
     connector._sweep_and_clean_cache(event_loop, 300)
     self.assertEqual(len(connector.lookups), 5)