git mv Ingress ingress
This commit is contained in:
parent
34b949c134
commit
3da4e74e5a
2185 changed files with 754743 additions and 0 deletions
275
controllers/nginx-third-party/lua/vendor/lua-resty-dns-cache/t/04-repopulate.t
vendored
Normal file
275
controllers/nginx-third-party/lua/vendor/lua-resty-dns-cache/t/04-repopulate.t
vendored
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
use lib 't';
|
||||
use TestDNS;
|
||||
use Cwd qw(cwd);
|
||||
|
||||
plan tests => repeat_each() * 17;
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;;";
|
||||
lua_socket_log_errors off;
|
||||
};
|
||||
|
||||
no_long_string();
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
=== TEST 1: Query is triggered when cache is expired
|
||||
--- http_config eval
|
||||
"$::HttpConfig"
|
||||
. q{
|
||||
lua_shared_dict dns_cache 1m;
|
||||
init_by_lua '
|
||||
local DNS_Cache = require("resty.dns.cache")
|
||||
DNS_Cache.init_cache()
|
||||
';
|
||||
}
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local DNS_Cache = require("resty.dns.cache")
|
||||
local dns, err = DNS_Cache.new({
|
||||
dict = "dns_cache",
|
||||
resolver = {nameservers = {{"127.0.0.1", "1953"}}},
|
||||
max_stale = 10
|
||||
})
|
||||
if not dns then
|
||||
ngx.say(err)
|
||||
end
|
||||
dns.resolver._id = 125
|
||||
|
||||
local answer, err, stale = dns:query("www.google.com", { qtype = dns.TYPE_A })
|
||||
if not answer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
local cjson = require"cjson"
|
||||
ngx.say(cjson.encode(answer))
|
||||
|
||||
dns._debug(true)
|
||||
|
||||
-- Sleep beyond response TTL
|
||||
ngx.sleep(1.1)
|
||||
|
||||
local answer, err, stale = dns:query("www.google.com", { qtype = dns.TYPE_A })
|
||||
if not answer then
|
||||
if stale then
|
||||
answer = stale
|
||||
else
|
||||
ngx.say(err)
|
||||
end
|
||||
end
|
||||
|
||||
local cjson = require"cjson"
|
||||
ngx.say(cjson.encode(answer))
|
||||
|
||||
ngx.sleep(0.1)
|
||||
|
||||
';
|
||||
}
|
||||
--- udp_listen: 1953
|
||||
--- udp_reply dns
|
||||
{
|
||||
id => 125,
|
||||
opcode => 0,
|
||||
qname => 'www.google.com',
|
||||
answer => [{ name => "www.google.com", ipv4 => "127.0.0.1", ttl => 1 }],
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- error_log
|
||||
Returning STALE
|
||||
Attempting to repopulate 'www.google.com'
|
||||
Repopulating 'www.google.com'
|
||||
--- response_body
|
||||
[{"address":"127.0.0.1","type":1,"class":1,"name":"www.google.com","ttl":1}]
|
||||
[{"address":"127.0.0.1","type":1,"class":1,"name":"www.google.com","ttl":0}]
|
||||
|
||||
=== TEST 2: Query is not triggered when cache expires and max_stale is disabled
|
||||
--- http_config eval
|
||||
"$::HttpConfig"
|
||||
. q{
|
||||
lua_shared_dict dns_cache 1m;
|
||||
init_by_lua '
|
||||
local DNS_Cache = require("resty.dns.cache")
|
||||
DNS_Cache.init_cache()
|
||||
';
|
||||
}
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local DNS_Cache = require("resty.dns.cache")
|
||||
local dns, err = DNS_Cache.new({
|
||||
dict = "dns_cache",
|
||||
resolver = {nameservers = {{"127.0.0.1", "1953"}}, retrans = 1, timeout = 50 },
|
||||
max_stale = 0
|
||||
})
|
||||
if not dns then
|
||||
ngx.say(err)
|
||||
end
|
||||
dns.resolver._id = 125
|
||||
|
||||
local answer, err, stale = dns:query("www.google.com", { qtype = dns.TYPE_A })
|
||||
if not answer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
dns._debug(true)
|
||||
|
||||
-- Sleep beyond response TTL
|
||||
ngx.sleep(1.1)
|
||||
|
||||
local answer, err, stale = dns:query("www.google.com", { qtype = dns.TYPE_A })
|
||||
if not answer then
|
||||
if stale then
|
||||
answer = stale
|
||||
else
|
||||
ngx.say(err)
|
||||
end
|
||||
end
|
||||
|
||||
local cjson = require"cjson"
|
||||
ngx.say(cjson.encode(answer))
|
||||
|
||||
ngx.sleep(0.1)
|
||||
';
|
||||
}
|
||||
--- udp_listen: 1953
|
||||
--- udp_reply dns
|
||||
{
|
||||
id => 125,
|
||||
opcode => 0,
|
||||
qname => 'www.google.com',
|
||||
answer => [{ name => "www.google.com", ipv4 => "127.0.0.1", ttl => 1 }],
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- no_error_log
|
||||
Attempting to repopulate 'www.google.com'
|
||||
Repopulating 'www.google.com'
|
||||
--- response_body
|
||||
[{"address":"127.0.0.1","type":1,"class":1,"name":"www.google.com","ttl":0}]
|
||||
|
||||
|
||||
=== TEST 3: Repopulate ignores max_stale
|
||||
--- http_config eval
|
||||
"$::HttpConfig"
|
||||
. q{
|
||||
lua_shared_dict dns_cache 1m;
|
||||
init_by_lua '
|
||||
local DNS_Cache = require("resty.dns.cache")
|
||||
DNS_Cache.init_cache()
|
||||
';
|
||||
}
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local DNS_Cache = require("resty.dns.cache")
|
||||
local dns, err = DNS_Cache.new({
|
||||
dict = "dns_cache",
|
||||
resolver = {nameservers = {{"127.0.0.1", "1953"}}, retrans = 1, timeout = 50 },
|
||||
max_stale = 10,
|
||||
})
|
||||
if not dns then
|
||||
ngx.say(err)
|
||||
end
|
||||
dns.resolver._id = 125
|
||||
dns._debug(true)
|
||||
|
||||
local answer, err, stale = dns:query("www.google.com", { qtype = dns.TYPE_A })
|
||||
if not answer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
-- Sleep beyond response TTL
|
||||
ngx.sleep(1.1)
|
||||
|
||||
local answer, err, stale = dns:query("www.google.com", { qtype = dns.TYPE_A })
|
||||
if not answer then
|
||||
if stale then
|
||||
answer = stale
|
||||
else
|
||||
ngx.say(err)
|
||||
end
|
||||
end
|
||||
|
||||
local cjson = require"cjson"
|
||||
ngx.say(cjson.encode(answer))
|
||||
|
||||
ngx.sleep(0.1)
|
||||
';
|
||||
}
|
||||
--- udp_listen: 1953
|
||||
--- udp_reply dns
|
||||
{
|
||||
id => 125,
|
||||
opcode => 0,
|
||||
qname => 'www.google.com',
|
||||
answer => [{ name => "www.google.com", ipv4 => "127.0.0.1", ttl => 1 }],
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- error_log
|
||||
Repopulating 'www.google.com'
|
||||
Querying: www.google.com
|
||||
Resolver error
|
||||
--- response_body
|
||||
[{"address":"127.0.0.1","type":1,"class":1,"name":"www.google.com","ttl":0}]
|
||||
|
||||
=== TEST 4: Multiple queries only trigger 1 repopulate timer
|
||||
--- http_config eval
|
||||
"$::HttpConfig"
|
||||
. q{
|
||||
lua_shared_dict dns_cache 1m;
|
||||
init_by_lua '
|
||||
local DNS_Cache = require("resty.dns.cache")
|
||||
DNS_Cache.init_cache()
|
||||
';
|
||||
}
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local DNS_Cache = require("resty.dns.cache")
|
||||
local dns, err = DNS_Cache.new({
|
||||
dict = "dns_cache",
|
||||
resolver = {nameservers = {{"127.0.0.1", "1953"}}, retrans = 1, timeout = 50 },
|
||||
repopulate = true,
|
||||
})
|
||||
if not dns then
|
||||
ngx.say(err)
|
||||
end
|
||||
dns.resolver._id = 125
|
||||
|
||||
local answer, err, stale = dns:query("www.google.com", { qtype = dns.TYPE_A })
|
||||
if not answer then
|
||||
ngx.say(err)
|
||||
end
|
||||
dns._debug(true)
|
||||
local answer, err, stale = dns:query("www.google.com", { qtype = dns.TYPE_A })
|
||||
if not answer then
|
||||
ngx.say(err)
|
||||
end
|
||||
local answer, err, stale = dns:query("www.google.com", { qtype = dns.TYPE_A })
|
||||
if not answer then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
local cjson = require"cjson"
|
||||
ngx.say(cjson.encode(answer))
|
||||
';
|
||||
}
|
||||
--- udp_listen: 1953
|
||||
--- udp_reply dns
|
||||
{
|
||||
id => 125,
|
||||
opcode => 0,
|
||||
qname => 'www.google.com',
|
||||
answer => [{ name => "www.google.com", ipv4 => "127.0.0.1", ttl => 1 }],
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- no_error_log
|
||||
Attempting to repopulate www.google.com
|
||||
--- response_body
|
||||
[{"address":"127.0.0.1","type":1,"class":1,"name":"www.google.com","ttl":1}]
|
||||
Loading…
Add table
Add a link
Reference in a new issue