MCPcopy Create free account
hub / github.com/cisco/mindmeld / test_memory_query_cache

Function test_memory_query_cache

tests/test_query_cache.py:64–98  ·  view source on GitHub ↗
(processed_queries)

Source from the content-addressed store, hash-verified

62
63
64def test_memory_query_cache(processed_queries):
65 environ = {
66 "MM_QUERY_CACHE_IN_MEMORY": "1",
67 "MM_QUERY_CACHE_WRITE_SIZE": "10"
68 }
69
70 with TemporaryDirectory() as tmpdir, patch.dict(os.environ, environ):
71 text_prep_pipeline = TextPreparationPipelineFactory.create_from_app_path(tmpdir)
72 cache = QueryCache(tmpdir, text_prep_pipeline.get_hashid())
73
74 # Verify that there is in-memory caching
75 assert cache.memory_connection is not None
76 for q in processed_queries[:9]:
77 key = QueryCache.get_key(q.domain, q.intent, q.query.text)
78 cache.put(key, q)
79 # Verify that the first 9 queries are not written to disk
80 assert not get_query_from_disk(tmpdir, key)
81
82 # Verify that the 10th query triggers a flush to disk
83 q = processed_queries[9]
84 key = QueryCache.get_key(q.domain, q.intent, q.query.text)
85 cache.put(key, q)
86 for q in processed_queries[:10]:
87 key = QueryCache.get_key(q.domain, q.intent, q.query.text)
88 assert get_query_from_disk(tmpdir, key) == (q.domain, q.intent, q.query.text)
89
90 # Verify that a GC triggers a flush to disk
91 for q in processed_queries[10:15]:
92 key = QueryCache.get_key(q.domain, q.intent, q.query.text)
93 cache.put(key, q)
94 assert not get_query_from_disk(tmpdir, key)
95 cache = None
96 for q in processed_queries[10:15]:
97 key = QueryCache.get_key(q.domain, q.intent, q.query.text)
98 assert get_query_from_disk(tmpdir, key)

Callers

nothing calls this directly

Calls 6

putMethod · 0.95
QueryCacheClass · 0.90
get_query_from_diskFunction · 0.85
create_from_app_pathMethod · 0.80
get_keyMethod · 0.80
get_hashidMethod · 0.45

Tested by

no test coverage detected