diff options
author | Matthew Wild <mwild1@gmail.com> | 2016-03-17 19:14:58 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2016-03-17 19:14:58 +0000 |
commit | 24a4b20169a9069e7a6db666696cfcd53b6dfba7 (patch) | |
tree | 7c73f01571fec72cf23febae41c64745cbd1a187 /tests | |
parent | 6b4c1ca955b953e05b4c4a56177142b19ecb3534 (diff) | |
download | prosody-24a4b20169a9069e7a6db666696cfcd53b6dfba7.tar.gz prosody-24a4b20169a9069e7a6db666696cfcd53b6dfba7.zip |
tests: util.cache: Tests for different return values of on_evict
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_util_cache.lua | 24 |
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 |