Skip to content

Commit

Permalink
fix(tcp) fix success reporting (#20)
Browse files Browse the repository at this point in the history
Bad name being called and a lack of tests. 2 regression tests
for TCP added

fixes #19
  • Loading branch information
Tieske authored and hishamhm committed May 10, 2019
1 parent 4155c27 commit f88c6f6
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/resty/healthcheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ function checker:run_single_check(ip, port, hostname)

if self.checks.active.type == "tcp" then
sock:close()
return self:report_tcp_success(ip, port, "active")
return self:report_success(ip, port, "active")
end

if self.checks.active.type == "https" then
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ for the complete API.

## History

### 0.6.x (xx-xxx-2019) UNRELEASED

* Fix: fix reporting active TCP probe successes
[#20](https://github.com/Kong/lua-resty-healthcheck/pull/20);
fixes issue [#19](https://github.com/Kong/lua-resty-healthcheck/issues/19)

### 0.6.1 (04-Apr-2019)

* Fix: set up event callback only after target list is loaded
Expand Down
109 changes: 106 additions & 3 deletions t/09-active_probes.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use Cwd qw(cwd);

workers(1);

plan tests => repeat_each() * 36;
plan tests => repeat_each() * 52;

my $pwd = cwd();

Expand All @@ -19,7 +19,7 @@ __DATA__



=== TEST 1: active probes, node failing
=== TEST 1: active probes, http node failing
--- http_config eval
qq{
$::HttpConfig
Expand Down Expand Up @@ -74,7 +74,7 @@ checking healthy targets: nothing to do



=== TEST 2: active probes, node recovering
=== TEST 2: active probes, http node recovering
--- http_config eval
qq{
$::HttpConfig
Expand Down Expand Up @@ -293,3 +293,106 @@ true
--- error_log
event: target status '127.0.0.1:2114' from 'false' to 'true'
checking unhealthy targets: nothing to do


=== TEST 6: active probes, tcp node failing
--- http_config eval
qq{
$::HttpConfig
}
--- 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 = "tcp",
checks = {
active = {
healthy = {
interval = 0.1,
successes = 3,
},
unhealthy = {
interval = 0.1,
tcp_failures = 3,
}
},
}
})
-- Note: no http server configured, so port 2114 remains unanswered
local ok, err = checker:add_target("127.0.0.1", 2114, nil, true)
ngx.sleep(0.5) -- wait for 5x the check interval
ngx.say(checker:get_target_status("127.0.0.1", 2114)) -- false
}
}
--- request
GET /t
--- response_body
false
--- error_log
checking unhealthy targets: nothing to do
unhealthy TCP increment (1/3) for 127.0.0.1:2114
unhealthy TCP increment (2/3) for 127.0.0.1:2114
unhealthy TCP increment (3/3) for 127.0.0.1:2114
event: target status '127.0.0.1:2114' from 'true' to 'false'
checking healthy targets: nothing to do



=== TEST 7: active probes, tcp node recovering
--- http_config eval
qq{
$::HttpConfig

server {
listen 2114;
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",
type = "tcp",
checks = {
active = {
http_path = "/status",
healthy = {
interval = 0.1,
successes = 3,
},
unhealthy = {
interval = 0.1,
tcp_failures = 3,
}
},
}
})
local ok, err = checker:add_target("127.0.0.1", 2114, nil, false)
ngx.sleep(0.5) -- wait for 5x the check interval
ngx.say(checker:get_target_status("127.0.0.1", 2114)) -- true
}
}
--- request
GET /t
--- response_body
true
--- error_log
checking healthy targets: nothing to do
healthy SUCCESS increment (1/3) for 127.0.0.1:2114
healthy SUCCESS increment (2/3) for 127.0.0.1:2114
healthy SUCCESS increment (3/3) for 127.0.0.1:2114
event: target status '127.0.0.1:2114' from 'false' to 'true'
checking unhealthy targets: nothing to do

0 comments on commit f88c6f6

Please sign in to comment.