-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_cache_decorator_time.py
37 lines (29 loc) · 1.12 KB
/
test_cache_decorator_time.py
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
#cache decorator test file. tests eviction based on elapsed time
import unittest
from cache_decorator import cached
import time
import logging
logging.basicConfig(level=logging.INFO)
class TestCacheDecoratorTime(unittest.TestCase):
def tearDown(self):
logging.debug("***********tearing down***********")
current_time.clear()
def test5minutesEviction(self):
sleepTime = 301;#5 min and 1 seconds
logging.info("Testing evict due to time. going to sleep for {0} seconds".format(sleepTime))
initial_value = current_time()
time.sleep(sleepTime)
self.assertNotEqual(current_time(), initial_value)
print(current_time.stat())
def testLessThan5minutesEviction(self):
sleepTime = 299;#5 min minus 1 second
logging.info("Testing evict due to time. going to sleep for {0} seconds".format(sleepTime))
initial_value = current_time()
time.sleep(sleepTime)
self.assertEqual(current_time(), initial_value)
print(current_time.stat())
@cached
def current_time():
return time.clock();
if __name__ == '__main__':
unittest.main()