aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2016-03-17 19:14:58 +0000
committerMatthew Wild <mwild1@gmail.com>2016-03-17 19:14:58 +0000
commitaa6d79191613b687877e39b54732d875ea0ee767 (patch)
tree7c73f01571fec72cf23febae41c64745cbd1a187
parent67ede3e0936f1e0dd396e18d56b040684b7b9842 (diff)
downloadprosody-aa6d79191613b687877e39b54732d875ea0ee767.tar.gz
prosody-aa6d79191613b687877e39b54732d875ea0ee767.zip
tests: util.cache: Tests for different return values of on_evict
-rw-r--r--tests/test_util_cache.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_util_cache.lua b/tests/test_util_cache.lua
index 155b154d..78666edc 100644
--- a/tests/test_util_cache.lua
+++ b/tests/test_util_cache.lua
@@ -271,4 +271,28 @@ function new(new)
expect_kv("c", 3, c4:head());
expect_kv("a", 1, c4:tail());
+ local c5 = new(3, function (k, v)
+ if k == "a" then
+ return nil;
+ elseif k == "b" then
+ return true;
+ end
+ return false;
+ end);
+
+ assert_equal(c5:set("a", 1), true);
+ assert_equal(c5:set("a", 1), true);
+ assert_equal(c5:set("a", 1), true);
+ assert_equal(c5:set("a", 1), true);
+ assert_equal(c5:set("b", 2), true);
+ assert_equal(c5:set("c", 3), true);
+ assert_equal(c5:set("d", 4), true); -- "a" evicted (cb returned nil)
+ assert_equal(c5:set("d", 4), true); -- nop
+ assert_equal(c5:set("d", 4), true); -- nop
+ assert_equal(c5:set("e", 5), true); -- "b" evicted (cb returned true)
+ assert_equal(c5:set("f", 6), false); -- "c" won't evict (cb returned false)
+
+ expect_kv("e", 5, c5:head());
+ expect_kv("c", 3, c5:tail());
+
end