-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(*): add number of timers check test
- Loading branch information
Showing
2 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use Test::Nginx::Socket::Lua; | ||
use Cwd qw(cwd); | ||
|
||
workers(1); | ||
|
||
plan tests => repeat_each() * blocks() * 2; | ||
|
||
my $pwd = cwd(); | ||
$ENV{TEST_NGINX_SERVROOT} = server_root(); | ||
|
||
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; | ||
access_log off; | ||
location / { | ||
content_by_lua_block { | ||
require("resty.events.compat").run() | ||
} | ||
} | ||
} | ||
}; | ||
|
||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
|
||
|
||
|
||
=== TEST 1: active probes, http node failing | ||
--- http_config eval | ||
qq{ | ||
$::HttpConfig | ||
|
||
server { | ||
listen 2130; | ||
location = /status { | ||
content_by_lua_block { | ||
ngx.sleep(2) | ||
ngx.exit(500); | ||
} | ||
} | ||
} | ||
} | ||
--- config | ||
location = /t { | ||
content_by_lua_block { | ||
local healthcheck = require("resty.healthcheck") | ||
local checker = healthcheck.new({ | ||
name = "testing", | ||
shm_name = "test_shm", | ||
type = "http", | ||
checks = { | ||
active = { | ||
timeout = 1, | ||
http_path = "/status", | ||
healthy = { | ||
interval = 0.1, | ||
successes = 3, | ||
}, | ||
unhealthy = { | ||
interval = 0.1, | ||
http_failures = 3, | ||
} | ||
}, | ||
} | ||
}) | ||
local ok, err = checker:add_target("127.0.0.1", 2130, nil, true) | ||
ngx.sleep(4) -- wait for some time to let the checks run | ||
-- There should be no more than 3 timers running atm, but | ||
-- add a few spaces for worker events | ||
ngx.say(tonumber(ngx.timer.running_count()) <= 5) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use Test::Nginx::Socket::Lua; | ||
use Cwd qw(cwd); | ||
|
||
workers(1); | ||
|
||
plan tests => repeat_each() * blocks() * 2; | ||
|
||
my $pwd = cwd(); | ||
|
||
our $HttpConfig = qq{ | ||
lua_package_path "$pwd/lib/?.lua;;"; | ||
lua_shared_dict test_shm 8m; | ||
lua_shared_dict my_worker_events 8m; | ||
}; | ||
|
||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
|
||
|
||
=== TEST 1: active probes, http node failing | ||
--- http_config eval | ||
qq{ | ||
$::HttpConfig | ||
|
||
server { | ||
listen 2130; | ||
location = /status { | ||
content_by_lua_block { | ||
ngx.sleep(2) | ||
ngx.exit(500); | ||
} | ||
} | ||
} | ||
} | ||
--- config | ||
location = /t { | ||
content_by_lua_block { | ||
local we = require "resty.worker.events" | ||
assert(we.configure{ shm = "my_worker_events", interval = 0.1 }) | ||
local healthcheck = require("resty.healthcheck") | ||
local checker = healthcheck.new({ | ||
name = "testing", | ||
shm_name = "test_shm", | ||
type = "http", | ||
checks = { | ||
active = { | ||
timeout = 1, | ||
http_path = "/status", | ||
healthy = { | ||
interval = 0.1, | ||
successes = 3, | ||
}, | ||
unhealthy = { | ||
interval = 0.1, | ||
http_failures = 3, | ||
} | ||
}, | ||
} | ||
}) | ||
local ok, err = checker:add_target("127.0.0.1", 2130, nil, true) | ||
ngx.sleep(4) -- wait for some time to let the checks run | ||
-- There should be no more than 3 timers running atm, but | ||
-- add a few spaces for worker events | ||
ngx.say(tonumber(ngx.timer.running_count()) <= 5) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
true |