Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
tests(*) reusage of timers, independent on # of workers
Browse files Browse the repository at this point in the history
  • Loading branch information
Murillo Paula committed May 28, 2021
1 parent 411e6fb commit a5214dc
Showing 1 changed file with 86 additions and 8 deletions.
94 changes: 86 additions & 8 deletions t/001-init.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use Test::Nginx::Socket 'no_plan';
use Test::Nginx::Socket;

plan tests => repeat_each() * (blocks() * 3) + 8;

workers(6);

run_tests();

Expand All @@ -12,23 +16,23 @@ qq {
assert(client.init())
local host = "httpbin.org"
local typ = client.TYPE_A
local answers, err = client.resolve(host, { qtype = typ })
ngx.log(ngx.ERR, "answers: ", answers)
ngx.log(ngx.ERR, err)
answers, err = client.resolve(host, { qtype = typ })
}
}
--- config
location = /t {
echo ok;
access_by_lua_block {
ngx.say("answers: ", answers)
ngx.say("err: ", err)
}
}
--- request
GET /t
--- response_body
ok
--- error_log
answers: nil
error: 101 empty record received
err: dns client error: 101 empty record received
--- no_error_log
[error]
dns lookup pool exceeded retries
API disabled in the context of init_worker_by_lua

Expand All @@ -43,13 +47,22 @@ API disabled in the context of init_worker_by_lua
local host = "httpbin.org"
local typ = client.TYPE_A
local answers, err = client.resolve(host, { qtype = typ })
if not answers then
ngx.say("failed to resolve: ", err)
end
ngx.say("address name: ", answers[1].name)
}
}
--- request
GET /t
--- response_body
address name: httpbin.org
--- no_error_log
[error]
dns lookup pool exceeded retries
API disabled in the context of init_worker_by_lua



Expand All @@ -73,3 +86,68 @@ ok
API disabled in the context of init_worker_by_lua
in function 'udp'
in function 'new'



=== TEST 4: reuse timers for queries of same name, independent on # of workers
--- http_config eval
qq {
init_worker_by_lua_block {
local client = require("resty.dns.client")
assert(client.init())
local host = "httpbin.org"
local typ = client.TYPE_A
for i = 1, 10 do
client.resolve(host, { qtype = typ })
end
local host = "mockbin.org"
for i = 1, 10 do
client.resolve(host, { qtype = typ })
end
workers = ngx.worker.count()
timers = ngx.timer.pending_count()
}
}
--- config
location = /t {
access_by_lua_block {
local client = require("resty.dns.client")
assert(client.init())
local host = "httpbin.org"
local typ = client.TYPE_A
local answers, err = client.resolve(host, { qtype = typ })
if not answers then
ngx.say("failed to resolve: ", err)
end
ngx.say("first address name: ", answers[1].name)
host = "mockbin.org"
answers, err = client.resolve(host, { qtype = typ })
if not answers then
ngx.say("failed to resolve: ", err)
end
ngx.say("second address name: ", answers[1].name)
ngx.say("workers: ", workers)
-- should be 2 timers maximum (1 for each hostname)
ngx.say("timers: ", timers)
}
}
--- request
GET /t
--- response_body
first address name: httpbin.org
second address name: mockbin.org
workers: 6
timers: 2
--- no_error_log
[error]
dns lookup pool exceeded retries
API disabled in the context of init_worker_by_lua

0 comments on commit a5214dc

Please sign in to comment.