-
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.
feat(*) add header support for active checks
- Loading branch information
Showing
3 changed files
with
125 additions
and
1 deletion.
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
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
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,114 @@ | ||
use Test::Nginx::Socket::Lua 'no_plan'; | ||
use Cwd qw(cwd); | ||
|
||
workers(1); | ||
|
||
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: req_headers: {"User-Agent", "curl/7.29.0"} | ||
--- http_config eval | ||
qq{ | ||
$::HttpConfig | ||
|
||
server { | ||
listen 2112; | ||
location = /status { | ||
return 200; | ||
} | ||
} | ||
} | ||
--- 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", | ||
checks = { | ||
active = { | ||
http_path = "/status", | ||
healthy = { | ||
interval = 0.1 | ||
}, | ||
req_headers = {"User-Agent: curl/7.29.0"} | ||
} | ||
} | ||
}) | ||
ngx.sleep(0.2) -- wait twice the interval | ||
local ok, err = checker:add_target("127.0.0.1", 2112, nil, true) | ||
ngx.say(ok) | ||
ngx.sleep(0.2) -- wait twice the interval | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
true | ||
--- error_log | ||
checking healthy targets: nothing to do | ||
checking healthy targets: #1 | ||
GET /status HTTP/1.0 | ||
User-Agent: curl/7.29.0 | ||
Host: 127.0.0.1 | ||
|
||
|
||
|
||
=== TEST 2: req_headers: {"User-Agent", "curl"} | ||
--- http_config eval | ||
qq{ | ||
$::HttpConfig | ||
|
||
server { | ||
listen 2112; | ||
location = /status { | ||
return 200; | ||
} | ||
} | ||
} | ||
--- 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", | ||
checks = { | ||
active = { | ||
http_path = "/status", | ||
healthy = { | ||
interval = 0.1 | ||
}, | ||
req_headers = {"User-Agent: curl"} | ||
} | ||
} | ||
}) | ||
ngx.sleep(0.2) -- wait twice the interval | ||
local ok, err = checker:add_target("127.0.0.1", 2112, nil, true) | ||
ngx.say(ok) | ||
ngx.sleep(0.2) -- wait twice the interval | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
true | ||
--- error_log | ||
checking healthy targets: nothing to do | ||
checking healthy targets: #1 | ||
GET /status HTTP/1.0 | ||
User-Agent: curl | ||
Host: 127.0.0.1 |