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 482e734
Showing 1 changed file with 90 additions and 11 deletions.
101 changes: 90 additions & 11 deletions t/001-init.t
Original file line number Diff line number Diff line change
@@ -1,40 +1,110 @@
use Test::Nginx::Socket 'no_plan';
use Test::Nginx::Socket;

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

workers(6);

no_shuffle();
run_tests();

__DATA__

=== TEST 1: init_worker: phase not supported by `semaphore:wait`
=== TEST 1: 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
local answers, err = client.resolve(host, { qtype = typ })
ngx.log(ngx.ERR, "answers: ", answers)
ngx.log(ngx.ERR, err)
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 {
echo ok;
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



=== TEST 2: init_worker: phase not supported by `semaphore:wait`
--- 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
answers, err = client.resolve(host, { qtype = typ })
}
}
--- config
location = /t {
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



=== TEST 2: access: phase supported by `semaphore:wait`
=== TEST 3: access: phase supported by `semaphore:wait`
--- config
location = /t {
access_by_lua_block {
Expand All @@ -43,17 +113,26 @@ 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



=== TEST 3: init_worker: phase not supported by lua-resty-dns `new` API
=== TEST 4: init_worker: phase not supported by lua-resty-dns `new` API
--- http_config eval
qq {
init_worker_by_lua_block {
Expand Down

0 comments on commit 482e734

Please sign in to comment.