(processed_queries)
| 62 | |
| 63 | |
| 64 | def 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) |
nothing calls this directly
no test coverage detected