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

fix(tests) init events module #107

Merged
merged 19 commits into from
Jun 10, 2022
18 changes: 10 additions & 8 deletions t/with_resty-events/01-start-stop.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ our $HttpConfig = qq{
lua_package_path "$pwd/lib/?.lua;;";
lua_shared_dict test_shm 8m;

init_worker_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({
unique_timeout = 5,
broker_id = 0,
listening = "unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock"
}))
assert(we.configured())
}

server {
server_name kong_worker_events;
listen unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock;
Expand All @@ -33,8 +43,6 @@ __DATA__
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
Expand Down Expand Up @@ -70,8 +78,6 @@ true
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
Expand Down Expand Up @@ -110,8 +116,6 @@ true
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
Expand Down Expand Up @@ -145,8 +149,6 @@ checking
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
Expand Down
22 changes: 13 additions & 9 deletions t/with_resty-events/02-add_target.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ our $HttpConfig = qq{
lua_package_path "$pwd/lib/?.lua;;";
lua_shared_dict test_shm 8m;

init_worker_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({
unique_timeout = 5,
broker_id = 0,
listening = "unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock"
}))
assert(we.configured())
}

server {
server_name kong_worker_events;
listen unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock;
Expand All @@ -33,13 +43,11 @@ __DATA__
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
shm_name = "test_shm",
events_module = "resty.events",
events_module = "resty.events",
checks = {
active = {
healthy = {
Expand Down Expand Up @@ -85,13 +93,11 @@ qq{
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
shm_name = "test_shm",
events_module = "resty.events",
events_module = "resty.events",
checks = {
active = {
http_path = "/status",
Expand Down Expand Up @@ -138,13 +144,11 @@ qq{
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
shm_name = "test_shm",
events_module = "resty.events",
events_module = "resty.events",
checks = {
active = {
http_path = "/status",
Expand Down
8 changes: 7 additions & 1 deletion t/with_resty-events/03-get_target_status.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ our $HttpConfig = qq{
init_worker_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({
unique_timeout = 5,
broker_id = 0,
listening = "unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock"
}))
assert(we.configured())
Expand Down Expand Up @@ -80,12 +82,16 @@ qq{
}
}
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2115, nil, true)
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2115)) -- true

checker:report_tcp_failure("127.0.0.1", 2115)
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2115)) -- false

checker:report_success("127.0.0.1", 2115)
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2115)) -- true
}
}
Expand Down
7 changes: 3 additions & 4 deletions t/with_resty-events/03-get_target_status_with_sleeps.t
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ qq{
}
}
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2115, nil, true)
ngx.sleep(0.1)
ngx.sleep(0.01)
ngx.say(checker:get_target_status("127.0.0.1", 2115)) -- true
checker:report_tcp_failure("127.0.0.1", 2115)
ngx.sleep(0.1)
ngx.sleep(0.01)
ngx.say(checker:get_target_status("127.0.0.1", 2115)) -- false
checker:report_success("127.0.0.1", 2115)
ngx.sleep(0.1)
ngx.sleep(0.01)
ngx.say(checker:get_target_status("127.0.0.1", 2115)) -- true
}
}
Expand Down
14 changes: 10 additions & 4 deletions t/with_resty-events/04-report_success.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ our $HttpConfig = qq{
init_worker_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({
unique_timeout = 5,
broker_id = 0,
listening = "unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock"
}))
assert(we.configured())
Expand Down Expand Up @@ -83,15 +85,16 @@ events_module = "resty.events",
}
}
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2116, nil, false)
local ok, err = checker:add_target("127.0.0.1", 2118, nil, false)
ngx.sleep(0.002)
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2116)) -- true
ngx.say(checker:get_target_status("127.0.0.1", 2118)) -- true
}
Expand Down Expand Up @@ -157,15 +160,16 @@ events_module = "resty.events",
}
}
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2116, nil, false)
local ok, err = checker:add_target("127.0.0.1", 2118, nil, false)
ngx.sleep(0.002)
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2118, nil, "passive")
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2116)) -- true
ngx.say(checker:get_target_status("127.0.0.1", 2118)) -- true
}
Expand Down Expand Up @@ -230,11 +234,12 @@ events_module = "resty.events",
}
}
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2116, nil, false)
ngx.sleep(0.002)
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2116, nil, "active")
checker:report_success("127.0.0.1", 2116, nil, "active")
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2116)) -- false
}
}
Expand Down Expand Up @@ -293,11 +298,12 @@ events_module = "resty.events",
}
}
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2118, nil, false)
ngx.sleep(0.002)
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2118, nil, "passive")
checker:report_success("127.0.0.1", 2118, nil, "passive")
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2118, nil)) -- false
}
}
Expand Down
31 changes: 19 additions & 12 deletions t/with_resty-events/05-report_failure.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ our $HttpConfig = qq{
lua_package_path "$pwd/lib/?.lua;;";
lua_shared_dict test_shm 8m;

init_worker_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({
unique_timeout = 5,
broker_id = 0,
listening = "unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock"
}))
assert(we.configured())
}

server {
server_name kong_worker_events;
listen unix:$ENV{TEST_NGINX_SERVROOT}/worker_events.sock;
Expand Down Expand Up @@ -45,13 +55,11 @@ qq{
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
shm_name = "test_shm",
events_module = "resty.events",
events_module = "resty.events",
type = "http",
checks = {
active = {
Expand All @@ -77,15 +85,16 @@ events_module = "resty.events",
}
}
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2117, nil, true)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, true)
ngx.sleep(0.002)
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2117, nil)) -- false
ngx.say(checker:get_target_status("127.0.0.1", 2113, nil)) -- false
}
Expand Down Expand Up @@ -121,13 +130,11 @@ qq{
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
shm_name = "test_shm",
events_module = "resty.events",
events_module = "resty.events",
type = "tcp",
checks = {
active = {
Expand All @@ -153,15 +160,16 @@ events_module = "resty.events",
}
}
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2117, nil, true)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, true)
ngx.sleep(0.002)
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2117, nil)) -- false
ngx.say(checker:get_target_status("127.0.0.1", 2113, nil)) -- false
}
Expand Down Expand Up @@ -195,13 +203,11 @@ qq{
--- config
location = /t {
content_by_lua_block {
local we = require "resty.events.compat"
assert(we.configure({ unique_timeout = 5, broker_id = 0, listening = "unix:" .. ngx.config.prefix() .. "worker_events.sock" }))
local healthcheck = require("resty.healthcheck")
local checker = healthcheck.new({
name = "testing",
shm_name = "test_shm",
events_module = "resty.events",
events_module = "resty.events",
type = "tcp",
checks = {
active = {
Expand All @@ -227,15 +233,16 @@ events_module = "resty.events",
}
}
})
ngx.sleep(0.1) -- wait for initial timers to run once
local ok, err = checker:add_target("127.0.0.1", 2117, nil, true)
local ok, err = checker:add_target("127.0.0.1", 2113, nil, true)
ngx.sleep(0.002)
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
checker:report_failure("127.0.0.1", 2117, nil, "active")
checker:report_failure("127.0.0.1", 2113, nil, "passive")
ngx.sleep(0.002)
ngx.say(checker:get_target_status("127.0.0.1", 2117, nil)) -- true
ngx.say(checker:get_target_status("127.0.0.1", 2113, nil)) -- true
}
Expand Down
Loading