Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(dns): fix individual_toip test failure due to cache hits #13114

Merged
merged 2 commits into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1506,19 +1506,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 @@ -1536,7 +1541,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
Loading