mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-11 01:10:56 +08:00
#4 added failing test for cache pruning
This commit is contained in:
@@ -21,7 +21,9 @@ class PruneProcessCache:
|
|||||||
def __call__(self):
|
def __call__(self):
|
||||||
while True:
|
while True:
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
|
self.prune()
|
||||||
|
|
||||||
|
def prune(self):
|
||||||
timestamp = current_time_stamp()
|
timestamp = current_time_stamp()
|
||||||
|
|
||||||
processes_to_delete = []
|
processes_to_delete = []
|
||||||
@@ -35,3 +37,4 @@ class PruneProcessCache:
|
|||||||
cache.prune(process)
|
cache.prune(process)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.getLogger("werkzeug").exception("failed to prune process")
|
logging.getLogger("werkzeug").exception("failed to prune process")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import unittest
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
from cellxgene_gateway.cache_entry import CacheEntry
|
||||||
|
from cellxgene_gateway.backend_cache import BackendCache
|
||||||
|
|
||||||
|
class TestPruneProcessCache(unittest.TestCase):
|
||||||
|
@patch('cellxgene_gateway.util.current_time_stamp', new=lambda:0)
|
||||||
|
@patch('cellxgene_gateway.env.ttl', new='10')
|
||||||
|
@patch('cellxgene_gateway.cache_entry.CacheEntry')
|
||||||
|
@patch('cellxgene_gateway.cache_entry.CacheEntry')
|
||||||
|
def test_GIVEN_one_old_one_new_THEN_prune_old(self, old, new):
|
||||||
|
from cellxgene_gateway.prune_process_cache import PruneProcessCache
|
||||||
|
|
||||||
|
cache = BackendCache()
|
||||||
|
old.timestamp = -100
|
||||||
|
cache.entry_list.append(old)
|
||||||
|
new.timestamp = -5
|
||||||
|
cache.entry_list.append(new)
|
||||||
|
self.assertEqual(len(cache.entry_list), 2)
|
||||||
|
ppc = PruneProcessCache(cache)
|
||||||
|
ppc.prune()
|
||||||
|
self.assertEqual(len(cache.entry_list), 1)
|
||||||
|
self.assertEqual(cache.entry_list[0], new)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user