|
| 1 | +"""Benchmarks for deleting data from cache.""" |
| 2 | + |
| 3 | +from pytest_benchmark.fixture import BenchmarkFixture |
| 4 | + |
| 5 | +from cache.noop_cache import NoopCache |
| 6 | + |
| 7 | +from .cache_data import ( |
| 8 | + CONVERSATION_ID_1, |
| 9 | + USER_ID, |
| 10 | + USER_PROVIDED_USER_ID, |
| 11 | + cache_entry_1, |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +def test_noop_cache_existing_conversation( |
| 16 | + noop_cache_fixture: NoopCache, benchmark: BenchmarkFixture |
| 17 | +) -> None: |
| 18 | + """Benchmark for deleting an existing conversation.""" |
| 19 | + noop_cache_fixture.insert_or_append(USER_ID, CONVERSATION_ID_1, cache_entry_1) |
| 20 | + benchmark(noop_cache_fixture.delete, USER_ID, CONVERSATION_ID_1) |
| 21 | + |
| 22 | + |
| 23 | +def test_noop_cache_nonexistent_conversation( |
| 24 | + noop_cache_fixture: NoopCache, benchmark: BenchmarkFixture |
| 25 | +) -> None: |
| 26 | + """Benchmark for deleting a conversation that doesn't exist.""" |
| 27 | + benchmark(noop_cache_fixture.delete, USER_ID, CONVERSATION_ID_1) |
| 28 | + |
| 29 | + |
| 30 | +def test_noop_cache_skip_user_id_check( |
| 31 | + noop_cache_fixture: NoopCache, benchmark: BenchmarkFixture |
| 32 | +) -> None: |
| 33 | + """Benchmark for deleting an existing conversation.""" |
| 34 | + skip_user_id_check = True |
| 35 | + noop_cache_fixture.insert_or_append( |
| 36 | + USER_PROVIDED_USER_ID, CONVERSATION_ID_1, cache_entry_1, skip_user_id_check |
| 37 | + ) |
| 38 | + |
| 39 | + benchmark( |
| 40 | + noop_cache_fixture.delete, |
| 41 | + USER_PROVIDED_USER_ID, |
| 42 | + CONVERSATION_ID_1, |
| 43 | + skip_user_id_check, |
| 44 | + ) |
0 commit comments