Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add upstream check test #264

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,20 @@ jobs:
sudo ln -s /home/runner/work/nginx-module-vts/nginx-module-vts/lua-resty-core/lib/resty/core.lua core.lua
sudo ln -s /home/runner/work/nginx-module-vts/nginx-module-vts/lua-resty-lrucache/lib/resty/lrucache lrucache
sudo ln -s /home/runner/work/nginx-module-vts/nginx-module-vts/lua-resty-lrucache/lib/resty/lrucache.lua lrucache.lua
- name: 'prepare nginx_upstream_check'
uses: actions/checkout@v3
with:
repository: yaoweibin/nginx_upstream_check_module
path: nginx_upstream_check

- name: 'patch upstream_check'
working-directory: nginx
run: |
patch -p1 < /home/runner/work/nginx-module-vts/nginx-module-vts/nginx_upstream_check/check_1.20.1+.patch
- name: 'build nginx'
working-directory: nginx
run: |
./auto/configure --with-ld-opt="-Wl,-rpath,/usr/local/lib" --without-pcre2 --add-module=/home/runner/work/nginx-module-vts/nginx-module-vts/ngx_devel_kit --add-module=/home/runner/work/nginx-module-vts/nginx-module-vts/lua-nginx-module --add-module=/home/runner/work/nginx-module-vts/nginx-module-vts/nginx-module-vts
./auto/configure --with-ld-opt="-Wl,-rpath,/usr/local/lib" --without-pcre2 --add-module=/home/runner/work/nginx-module-vts/nginx-module-vts/ngx_devel_kit --add-module=/home/runner/work/nginx-module-vts/nginx-module-vts/lua-nginx-module --add-module=/home/runner/work/nginx-module-vts/nginx-module-vts/nginx-module-vts --add-module=/home/runner/work/nginx-module-vts/nginx-module-vts/nginx_upstream_check
make
sudo make install
/usr/local/nginx/sbin/nginx -V
Expand All @@ -83,3 +93,11 @@ jobs:
run: |
echo "/usr/local/nginx/sbin/" >> $GITHUB_PATH
sudo PATH=/usr/local/nginx/sbin:$PATH prove -r t
- name: 'test upstream check'
working-directory: nginx-module-vts
run: |
echo "/usr/local/nginx/sbin/" >> $GITHUB_PATH
sudo PATH=/usr/local/nginx/sbin:$PATH prove t/024.upstream_check.t
env:
TEST_UPSTREAM_CHECK: 1
TEST_NGINX_SLEEP: 1
64 changes: 64 additions & 0 deletions t/024.upstream_check.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# vi:set ft=perl ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket;

master_on;
plan skip_all => 'nginx_upstream_check test skipped' unless $ENV{TEST_UPSTREAM_CHECK};
plan tests => 4;
no_shuffle();
run_tests();

__DATA__
=== TEST 1: upstream peer->down is true
--- http_config
vhost_traffic_status_zone;
upstream backend {
zone backend 64k;
server localhost:8080;
check interval=1000 rise=1 fall=1 timeout=1000;
}
--- config
location /backend {
proxy_pass http://backend;
}
location /status {
check_status;
vhost_traffic_status_display;
vhost_traffic_status_display_format json;
access_log off;
}
--- request
GET /status
--- response_body_like eval
'"down":true'
=== TEST 2: upstream peer->down is false
--- http_config
vhost_traffic_status_zone;
upstream backend {
zone backend 64k;
server localhost:8080;
check interval=1000 rise=1 fall=1 timeout=1000;
}
server {
listen 8080;
server_name localhost;
location / {
root html;
}
}
--- config
location /index.html {
proxy_pass http://backend;
}
location /status {
check_status;
vhost_traffic_status_display;
vhost_traffic_status_display_format json;
access_log off;
}
--- request
GET /status
--- response_body_like eval
'"down":false'