free(result);
- /* Ensure eviction happened by checking that only one of the two
- * previously-added items can still be fetched.
+ /* Ensure eviction happened by checking that both of the previous
+ * cache itesm were evicted.
*/
+ bool contains_1KB_file = false;
count = 0;
if (does_cache_contain(cache, blob_key))
count++;
if (does_cache_contain(cache, string_key))
count++;
+ if (does_cache_contain(cache, one_KB_key)) {
+ count++;
+ contains_1KB_file = true;
+ }
+
+ expect_true(contains_1KB_file,
+ "disk_cache_put eviction last file == MAX_SIZE (1KB)");
expect_equal(count, 1, "disk_cache_put eviction with MAX_SIZE=1K");
/* Now increase the size to 1M, add back both items, and ensure all
*/
wait_until_file_written(cache, one_MB_key);
+ bool contains_1MB_file = false;
count = 0;
if (does_cache_contain(cache, blob_key))
count++;
if (does_cache_contain(cache, one_KB_key))
count++;
- expect_equal(count, 2, "eviction after overflow with MAX_SIZE=1M");
+ if (does_cache_contain(cache, one_MB_key)) {
+ count++;
+ contains_1MB_file = true;
+ }
+
+ expect_true(contains_1MB_file,
+ "disk_cache_put eviction last file == MAX_SIZE (1MB)");
+ expect_equal(count, 1, "eviction after overflow with MAX_SIZE=1M");
disk_cache_destroy(cache);
}
assert(job);
int fd = -1, fd_final = -1, err, ret;
+ unsigned i = 0;
size_t len;
char *filename = NULL, *filename_tmp = NULL;
struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *) job;
* Before we do that, if the cache is too large, evict something
* else first.
*/
- if (*dc_job->cache->size + dc_job->size > dc_job->cache->max_size)
+ while ((*dc_job->cache->size + dc_job->size > dc_job->cache->max_size) &&
+ i < 8) {
evict_lru_item(dc_job->cache);
+ i++;
+ }
/* Create CRC of the data and store at the start of the file. We will
* read this when restoring the cache and use it to check for corruption.