-
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.
- Loading branch information
Showing
48 changed files
with
4,877 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Build and test | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
name: CI using lua-resty-worker-events | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
matrix: | ||
openresty-version: [1.15.8.3, 1.17.8.2, 1.19.9.1, 1.21.4.1] | ||
|
||
steps: | ||
- name: Update and install OS dependencies | ||
run: | | ||
sudo apt-get update && sudo apt-get install -y libssl-dev ssl-cert | ||
sudo systemctl disable nginx | ||
sudo systemctl stop nginx | ||
- name: Set environment variables | ||
env: | ||
OPENRESTY_VER: ${{ matrix.openresty-version }} | ||
run: | | ||
echo "/usr/local/openresty/nginx/sbin" >> $GITHUB_PATH | ||
- name: Checkout lua-resty-healthcheck | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install OpenResty ${{ matrix.openresty-version }} | ||
env: | ||
OPENRESTY_VER: ${{ matrix.openresty-version }} | ||
run: | | ||
sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates | ||
wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add - | ||
echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/openresty.list | ||
sudo apt-get update | ||
sudo apt-get -y install openresty=$OPENRESTY_VER-1~focal1 | ||
- name: Install LuaRocks | ||
run: sudo apt-get install -y luarocks | ||
|
||
- name: Install manual dependencies | ||
run: | | ||
sudo luarocks install luacheck | ||
sudo luarocks install lua-resty-worker-events 1.0.0 | ||
- name: Install Test::NGINX | ||
run: | | ||
sudo apt-get install cpanminus | ||
cpanm --notest --local-lib=$HOME/perl5 local::lib && eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) | ||
cpanm --notest Test::Nginx | ||
- name: Checkout lua-resty-healthcheck | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install lua-resty-healthcheck | ||
run: sudo luarocks make | ||
|
||
- name: Run tests | ||
run: | | ||
eval `luarocks path` | ||
eval $(perl -I $HOME/perl5/lib/perl5/ -Mlocal::lib) | ||
TEST_NGINX_RANDOMIZE=1 prove -I. -r t/with_worker-events |
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,229 @@ | ||
use Test::Nginx::Socket::Lua; | ||
use Cwd qw(cwd); | ||
|
||
workers(1); | ||
|
||
plan tests => repeat_each() * (blocks() * 3) - 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; | ||
|
||
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: new() requires worker_events to be configured | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location = /t { | ||
content_by_lua_block { | ||
local healthcheck = require("resty.healthcheck") | ||
local ok, err = pcall(healthcheck.new, { | ||
events_module = "resty.events", | ||
}) | ||
ngx.log(ngx.ERR, err) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
|
||
--- error_log | ||
please configure | ||
|
||
=== TEST 2: new() requires 'name' | ||
--- http_config eval: $::HttpConfig | ||
--- 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 ok, err = pcall(healthcheck.new, { | ||
events_module = "resty.events", | ||
shm_name = "test_shm", | ||
}) | ||
ngx.log(ngx.ERR, err) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
|
||
--- error_log | ||
required option 'name' is missing | ||
|
||
=== TEST 3: new() fails with invalid shm | ||
--- http_config eval: $::HttpConfig | ||
--- 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 ok, err = pcall(healthcheck.new, { | ||
name = "testing", | ||
shm_name = "invalid_shm", | ||
events_module = "resty.events", | ||
}) | ||
ngx.log(ngx.ERR, err) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
|
||
--- error_log | ||
no shm found by name | ||
|
||
=== TEST 4: new() initializes with default config | ||
--- http_config eval: $::HttpConfig | ||
--- 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 ok, err = pcall(healthcheck.new, { | ||
name = "testing", | ||
shm_name = "test_shm", | ||
events_module = "resty.events", | ||
}) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
|
||
--- error_log | ||
Healthchecker started! | ||
|
||
=== TEST 5: new() only accepts http or tcp types | ||
--- http_config eval: $::HttpConfig | ||
--- 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 ok, err = pcall(healthcheck.new, { | ||
name = "testing", | ||
shm_name = "test_shm", | ||
events_module = "resty.events", | ||
type = "http", | ||
}) | ||
ngx.say(ok) | ||
local ok, err = pcall(healthcheck.new, { | ||
name = "testing", | ||
shm_name = "test_shm", | ||
events_module = "resty.events", | ||
type = "tcp", | ||
}) | ||
ngx.say(ok) | ||
local ok, err = pcall(healthcheck.new, { | ||
name = "testing", | ||
shm_name = "test_shm", | ||
events_module = "resty.events", | ||
type = "get lost", | ||
}) | ||
ngx.say(ok) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
true | ||
true | ||
false | ||
|
||
=== TEST 6: new() deals with bad inputs | ||
--- http_config eval: $::HttpConfig | ||
--- 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") | ||
|
||
-- tests for failure | ||
local tests = { | ||
{ active = { timeout = -1 }}, | ||
{ active = { timeout = 1e+42 }}, | ||
{ active = { concurrency = -1 }}, | ||
{ active = { concurrency = 1e42 }}, | ||
{ active = { healthy = { interval = -1 }}}, | ||
{ active = { healthy = { interval = 1e42 }}}, | ||
{ active = { healthy = { successes = -1 }}}, | ||
{ active = { healthy = { successes = 1e42 }}}, | ||
{ active = { unhealthy = { interval = -1 }}}, | ||
{ active = { unhealthy = { interval = 1e42 }}}, | ||
{ active = { unhealthy = { tcp_failures = -1 }}}, | ||
{ active = { unhealthy = { tcp_failures = 1e42 }}}, | ||
{ active = { unhealthy = { timeouts = -1 }}}, | ||
{ active = { unhealthy = { timeouts = 1e42 }}}, | ||
{ active = { unhealthy = { http_failures = -1 }}}, | ||
{ active = { unhealthy = { http_failures = 1e42 }}}, | ||
{ passive = { healthy = { successes = -1 }}}, | ||
{ passive = { healthy = { successes = 1e42 }}}, | ||
{ passive = { unhealthy = { tcp_failures = -1 }}}, | ||
{ passive = { unhealthy = { tcp_failures = 1e42 }}}, | ||
{ passive = { unhealthy = { timeouts = -1 }}}, | ||
{ passive = { unhealthy = { timeouts = 1e42 }}}, | ||
{ passive = { unhealthy = { http_failures = -1 }}}, | ||
{ passive = { unhealthy = { http_failures = 1e42 }}}, | ||
} | ||
for _, test in ipairs(tests) do | ||
local ok, err = pcall(healthcheck.new, { | ||
name = "testing", | ||
shm_name = "test_shm", | ||
events_module = "resty.events", | ||
type = "http", | ||
checks = test, | ||
}) | ||
ngx.say(ok) | ||
end | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false | ||
false |
Oops, something went wrong.