def test_no_ttl(self): l = TTLRU(2) l.set_with_ttl(0, 0, -1) l.set_with_ttl(1, 1, int(20e6)) self.assertEqual(l.items(), [(1, 1), (0, 0)]) time.sleep(0.02) # approximately 0.02s self.assertEqual(l.items(), [(0, 0)]) time.sleep(0.02) # approximately 0.04s self.assertEqual(l.items(), [(0, 0)])
def test_replace_key_with_ttl(self): l = TTLRU(2, ttl=int(20e6)) l[1] = 1 self.assertEqual(l.items(), [(1, 1)]) time.sleep(0.01) # approximately 0.01s self.assertEqual(l.items(), [(1, 1)]) l[1] = 2 self.assertEqual(l.items(), [(1, 2)]) time.sleep(0.01) # approximately 0.01s self.assertEqual(l.items(), [(1, 2)]) time.sleep(0.01) # approximately 0.03s self.assertEqual(l.items(), [])