| 140 | assert cache.hits == 2 |
| 141 | |
| 142 | def test_backoff(self, cache: RepositoryCache): |
| 143 | def query_size_limit(): |
| 144 | cache.size_limit = 0 |
| 145 | |
| 146 | assert [pdchunk(ch) for ch in cache.get_many([H(1), H(2)])] == [b"1234", b"5678"] |
| 147 | assert cache.misses == 2 |
| 148 | assert cache.evictions == 0 |
| 149 | iterator = cache.get_many([H(1), H(3), H(2)]) |
| 150 | assert pdchunk(next(iterator)) == b"1234" |
| 151 | |
| 152 | # Force cache to back off |
| 153 | qsl = cache.query_size_limit |
| 154 | cache.query_size_limit = query_size_limit # type: ignore[assignment] |
| 155 | cache.backoff() |
| 156 | cache.query_size_limit = qsl # type: ignore[assignment] |
| 157 | # Evicted H(1) and H(2) |
| 158 | assert cache.evictions == 2 |
| 159 | assert H(1) not in cache.cache |
| 160 | assert H(2) not in cache.cache |
| 161 | assert pdchunk(next(iterator)) == bytes(100) |
| 162 | assert cache.slow_misses == 0 |
| 163 | # Since H(2) was in the cache when we called get_many(), but has |
| 164 | # been evicted during iterating the generator, it will be a slow miss. |
| 165 | assert pdchunk(next(iterator)) == b"5678" |
| 166 | assert cache.slow_misses == 1 |
| 167 | |
| 168 | def test_enospc(self, cache: RepositoryCache): |
| 169 | class enospc_open: |