def test_get_refresh_list_noforce(self): now = util.now() minimal_bad_timestamp = now - constants.REFRESH_TIMEOUT rt = self._make_rt_with_n_buckets(5) stale_idxs = (0, 3) for idx in stale_idxs: rt[idx].last_accessed = minimal_bad_timestamp refresh_list = sorted(rt.get_refresh_list()) self.assertEqual(len(refresh_list), 2) self.assertTrue(rt[0].guid_in_range(refresh_list[0])) self.assertTrue(rt[3].guid_in_range(refresh_list[1]))
def __init__(self, range_min, range_max): """ Make a new KBucket with the specified range. Args: range_min, range_max: The lower and upper limits for the range in the ID space covered by this KBucket, as integers. This is a half-open range: [range_min, range_max) """ self.last_accessed = util.now() self.range_min = range_min self.range_max = range_max # This list of contacts implements an LRU-protocol: # Fresh or updated contacts are near the tail of the list, # while stale contacts are near the head. self._contacts = []
def test_is_stale(self): self.bucket.last_accessed = util.now() - constants.REFRESH_TIMEOUT self.assertTrue(self.bucket.is_stale()) self.bucket.last_accessed = util.now() self.assertFalse(self.bucket.is_stale())
def updating_method(self, *args, **kwargs): self.last_accessed = util.now() return func(self, *args, **kwargs)
def is_stale(self): return util.now() - self.last_accessed >= constants.REFRESH_TIMEOUT