Skip to content

Commit

Permalink
tests(dns): fix individual_toip test failure due to cache hits (#13114)
Browse files Browse the repository at this point in the history
* used empty search option to avoid generating extra query for search domains
* introduced some delays in the queries of background coroutines to avoid cache hits

KAG-4520
  • Loading branch information
chobits authored and AndyZhang0707 committed Jun 3, 2024
1 parent 3bbad19 commit 7f502fb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions spec/01-unit/21-dns-client/02-client_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1513,19 +1513,24 @@ describe("[DNS client]", function()
assert(client.init({
noSynchronisation = false,
order = { "A" },
search = {},
}))

local callcount = 0
query_func = function(self, original_query_func, name, options)
callcount = callcount + 1
return original_query_func(self, name, options)
-- Introducing a simulated network delay ensures individual_toip always
-- triggers a DNS query to avoid it triggering only once due to a cache
-- hit. 0.1 second is enough.
ngx.sleep(0.1)
return {{ type = client.TYPE_A, address = "1.1.1.1", class = 1, name = name, ttl = 10 } }
end

-- assert synchronisation is working
local threads = {}
for i=1,resolve_count do
threads[i] = ngx.thread.spawn(function()
local ip = client.toip("smtp." .. TEST_DOMAIN)
local ip = client.toip("toip.com")
assert.is_string(ip)
end)
end
Expand All @@ -1543,7 +1548,7 @@ describe("[DNS client]", function()
threads = {}
for i=1,resolve_count do
threads[i] = ngx.thread.spawn(function()
local ip = client.individual_toip("atest." .. TEST_DOMAIN)
local ip = client.individual_toip("individual_toip.com")
assert.is_string(ip)
end)
end
Expand Down

0 comments on commit 7f502fb

Please sign in to comment.