Skip to content

Commit

Permalink
test: Add upstream check test
Browse files Browse the repository at this point in the history
relivant: #227, #258, #262
  • Loading branch information
u5surf committed Mar 12, 2023
1 parent 5b3812e commit d3ac15a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
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_module
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'

0 comments on commit d3ac15a

Please sign in to comment.