Software /
code /
prosody
Changeset
7291:688a7f5d3624
tests: util.cache: Tests for different return values of on_evict
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 17 Mar 2016 19:14:58 +0000 |
parents | 7290:70ab13e81cf5 |
children | 7292:ec1748626924 7293:c4af754d1e1b |
files | tests/test_util_cache.lua |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test_util_cache.lua Thu Mar 17 19:08:42 2016 +0000 +++ b/tests/test_util_cache.lua Thu Mar 17 19:14:58 2016 +0000 @@ -271,4 +271,28 @@ 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