-
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.
fix(*): avoid creating multiple timers to run the same active check (#…
…156)
- Loading branch information
Showing
5 changed files
with
231 additions
and
12 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
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,93 @@ | ||
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", | ||
events_module = "resty.events", | ||
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(3) -- 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
Oops, something went wrong.