Verified Commit 7ac4a454 authored by Petr Špaček's avatar Petr Špaček Committed by Vladimír Čunát

cache.clear: clearing root clears everything, not only the root zone

Problem was caused by our lookup format where only the root zone starts
with \0 and all other zones start differently. This caused
cache_match('.') to match only data from root zone.
parent 083ea00a
......@@ -79,3 +79,4 @@ files['daemon/lua/kres-gen.lua'].ignore = {'631'} -- Allow overly long lines
files['scripts'].ignore = {'111', '112', '113'}
files['tests'].ignore = {'111', '112', '113'}
files['modules/**/*.test.lua'].ignore = {'111', '112', '113', '121', '122'}
files['daemon/**/*.test.lua'].ignore = {'111', '112', '113', '121', '122'}
......@@ -26,9 +26,9 @@ assert(net.interfaces() ~= nil)
-- Self-checks on loaded stuff
assert(#modules.list() > 0)
-- Self-check timers
ev = event.recurrent(1 * sec, function (ev) return 1 end)
ev = event.recurrent(1 * sec, function () return 1 end)
event.cancel(ev)
ev = event.after(0, function (ev) return 1 end)
ev = event.after(0, function () return 1 end)
-- import fake root zone
......@@ -61,8 +61,8 @@ local function import_zone()
worker.sleep(0.2) -- zimport is delayed by 100 ms from function call
-- sanity checks - cache must be filled in
ok(cache.count() > 0, 'cache is not empty after import')
check_answer('root apex is cache',
'.', kres.type.NS, kres.rcode.NOERROR)
check_answer('root apex is in cache',
'.', kres.type.NS, kres.rcode.NOERROR)
check_answer('deep subdomain is in cache',
'a.b.subtree1.', kres.type.AAAA, kres.rcode.NOERROR)
......@@ -120,23 +120,22 @@ end
local function test_callback()
local test_name = '20r.subtree2.'
local test_maxcount = 1
local test_exactname = true
local test_rrtype = nil
local test_maxcount = 1
local test_chunksize = 1
local test_prev_state = { works = true }
local function check_callback(name, exact_name, rr_type, chunk_size, callback, prev_state, errors)
is(errors.count, 1, 'callback received correct # of removed records')
is(test_name, name, 'callback received subtree name')
is(test_exactname, exact_name, 'callback received exact_name')
is(test_rrtype, rrtype, 'callback received rr_type')
is(test_chunksize, chunksize, 'callback received maxcount')
is(test_rrtype, rr_type, 'callback received rr_type')
is(test_chunksize, chunk_size, 'callback received chunk_size')
is(check_callback, callback, 'callback received reference to itself')
is(type(errors), 'table', 'callback received table of errors')
same(test_prev_state, prev_state, 'callback received previous state')
return 666
end
same(cache.clear(test_name, test_exactname, test_rrtype, test_maxcount, check_callback, test_prev_state),
same(cache.clear(test_name, test_exactname, test_rrtype, test_chunksize, check_callback, test_prev_state),
666, 'first callback return value is passed to cache.clear() caller')
local cnt_before_wait = cache.count()
worker.sleep(0.2)
......@@ -173,6 +172,13 @@ local function test_apex()
'a.b.subtree1.', kres.type.NULL, kres.rcode.SERVFAIL)
end
local function test_root()
local prev_count = cache.count()
res = cache.clear('.')
is(res.count, prev_count, 'full clear reports correct number of entries')
is(cache.count(), 0, 'clearing root clears everything')
end
local function test_complete_flush()
local prev_count = cache.count()
res = cache.clear()
......@@ -190,5 +196,7 @@ return {
test_subtree_limit,
test_apex,
import_zone,
test_root,
import_zone,
test_complete_flush,
}
......@@ -159,7 +159,8 @@ setmetatable(modules, {
cache.clear = function (name, exact_name, rr_type, chunk_size, callback, prev_state)
if name == nil then -- keep same output format as for 'standard' clear
if name == nil or (name == '.' and not exact_name) then
-- keep same output format as for 'standard' clear
local total_count = cache.count()
if not cache.clear_everything() then
error('unable to clear everything')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment