aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-06-30 22:01:49 +0200
committerKim Alvefur <zash@zash.se>2023-06-30 22:01:49 +0200
commit29b6ed4f0a40f0f595d21537e1308f744b9a4907 (patch)
tree021def1fc118a9a7594d0369c120912811c25cc8 /spec
parent8ba5e50cc295e820ec188a80f6459b69bde2d8f9 (diff)
downloadprosody-29b6ed4f0a40f0f595d21537e1308f744b9a4907.tar.gz
prosody-29b6ed4f0a40f0f595d21537e1308f744b9a4907.zip
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.
Diffstat (limited to 'spec')
-rw-r--r--spec/util_cache_spec.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/util_cache_spec.lua b/spec/util_cache_spec.lua
index 2cb7b7dd..d4e609ed 100644
--- a/spec/util_cache_spec.lua
+++ b/spec/util_cache_spec.lua
@@ -388,5 +388,26 @@ describe("util.cache", function()
c:resize(3);
assert.same({"v5", "v4", "v3"}, vs(c));
end);
+
+ it("eviction stuff", function ()
+ local c;
+ c = cache.new(4, function(_k,_v)
+ if c.size < 10 then
+ c:resize(c.size*2);
+ end
+ end)
+ for i = 1,20 do
+ c:set(i,i)
+ end
+ assert.equal(16, c.size);
+ assert.is_nil(c:get(1))
+ assert.is_nil(c:get(4))
+ assert.equal(5, c:get(5))
+ assert.equal(20, c:get(20))
+ c:resize(4)
+ assert.equal(20, c:get(20))
+ assert.equal(17, c:get(17))
+ assert.is_nil(c:get(10))
+ end)
end);
end);