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 May 31, 2024
1 parent e2aed1d commit 9641d9b
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 @@ -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

1 comment on commit 9641d9b

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:9641d9ba3094862442bb01e4bad8f9ad344e4f06
Artifacts available https://github.com/Kong/kong/actions/runs/9315117142

Please sign in to comment.