Software /
code /
prosody
Comparison
spec/util_cache_spec.lua @ 13174:8ec7b7d6556f
util.cache: Keep eviction candidate if callback resized to make room
Previously either the old or the new values would be rejected, even if
the cache was resized to allow more items.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 30 Jun 2023 22:01:49 +0200 |
parent | 12771:e9fcc69ea508 |
child | 13175:bbdaa770b955 |
comparison
equal
deleted
inserted
replaced
13173:4906d4990ffe | 13174:8ec7b7d6556f |
---|---|
386 c:resize("foo"); | 386 c:resize("foo"); |
387 end); | 387 end); |
388 c:resize(3); | 388 c:resize(3); |
389 assert.same({"v5", "v4", "v3"}, vs(c)); | 389 assert.same({"v5", "v4", "v3"}, vs(c)); |
390 end); | 390 end); |
391 | |
392 it("eviction stuff", function () | |
393 local c; | |
394 c = cache.new(4, function(_k,_v) | |
395 if c.size < 10 then | |
396 c:resize(c.size*2); | |
397 end | |
398 end) | |
399 for i = 1,20 do | |
400 c:set(i,i) | |
401 end | |
402 assert.equal(16, c.size); | |
403 assert.is_nil(c:get(1)) | |
404 assert.is_nil(c:get(4)) | |
405 assert.equal(5, c:get(5)) | |
406 assert.equal(20, c:get(20)) | |
407 c:resize(4) | |
408 assert.equal(20, c:get(20)) | |
409 assert.equal(17, c:get(17)) | |
410 assert.is_nil(c:get(10)) | |
411 end) | |
391 end); | 412 end); |
392 end); | 413 end); |