Skip to content

Commit cfc59fa

Browse files
authored
Merge pull request #264 from u5surf/add_upstream_check_test
test: Add upstream check test
2 parents 5b3812e + 41a7ceb commit cfc59fa

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,20 @@ jobs:
5858
sudo ln -s /home/runner/work/nginx-module-vts/nginx-module-vts/lua-resty-core/lib/resty/core.lua core.lua
5959
sudo ln -s /home/runner/work/nginx-module-vts/nginx-module-vts/lua-resty-lrucache/lib/resty/lrucache lrucache
6060
sudo ln -s /home/runner/work/nginx-module-vts/nginx-module-vts/lua-resty-lrucache/lib/resty/lrucache.lua lrucache.lua
61+
- name: 'prepare nginx_upstream_check'
62+
uses: actions/checkout@v3
63+
with:
64+
repository: yaoweibin/nginx_upstream_check_module
65+
path: nginx_upstream_check
66+
67+
- name: 'patch upstream_check'
68+
working-directory: nginx
69+
run: |
70+
patch -p1 < /home/runner/work/nginx-module-vts/nginx-module-vts/nginx_upstream_check/check_1.20.1+.patch
6171
- name: 'build nginx'
6272
working-directory: nginx
6373
run: |
64-
./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
74+
./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
6575
make
6676
sudo make install
6777
/usr/local/nginx/sbin/nginx -V
@@ -83,3 +93,11 @@ jobs:
8393
run: |
8494
echo "/usr/local/nginx/sbin/" >> $GITHUB_PATH
8595
sudo PATH=/usr/local/nginx/sbin:$PATH prove -r t
96+
- name: 'test upstream check'
97+
working-directory: nginx-module-vts
98+
run: |
99+
echo "/usr/local/nginx/sbin/" >> $GITHUB_PATH
100+
sudo PATH=/usr/local/nginx/sbin:$PATH prove t/024.upstream_check.t
101+
env:
102+
TEST_UPSTREAM_CHECK: 1
103+
TEST_NGINX_SLEEP: 1

t/024.upstream_check.t

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# vi:set ft=perl ts=4 sw=4 et fdm=marker:
2+
3+
use Test::Nginx::Socket;
4+
5+
master_on;
6+
plan skip_all => 'nginx_upstream_check test skipped' unless $ENV{TEST_UPSTREAM_CHECK};
7+
plan tests => 4;
8+
no_shuffle();
9+
run_tests();
10+
11+
__DATA__
12+
13+
=== TEST 1: upstream peer->down is true
14+
--- http_config
15+
vhost_traffic_status_zone;
16+
upstream backend {
17+
zone backend 64k;
18+
server localhost:8080;
19+
check interval=1000 rise=1 fall=1 timeout=1000;
20+
}
21+
--- config
22+
location /backend {
23+
proxy_pass http://backend;
24+
}
25+
location /status {
26+
check_status;
27+
vhost_traffic_status_display;
28+
vhost_traffic_status_display_format json;
29+
access_log off;
30+
}
31+
--- request
32+
GET /status
33+
--- response_body_like eval
34+
'"down":true'
35+
36+
=== TEST 2: upstream peer->down is false
37+
--- http_config
38+
vhost_traffic_status_zone;
39+
upstream backend {
40+
zone backend 64k;
41+
server localhost:8080;
42+
check interval=1000 rise=1 fall=1 timeout=1000;
43+
}
44+
server {
45+
listen 8080;
46+
server_name localhost;
47+
location / {
48+
root html;
49+
}
50+
}
51+
--- config
52+
location /index.html {
53+
proxy_pass http://backend;
54+
}
55+
location /status {
56+
check_status;
57+
vhost_traffic_status_display;
58+
vhost_traffic_status_display_format json;
59+
access_log off;
60+
}
61+
--- request
62+
GET /status
63+
--- response_body_like eval
64+
'"down":false'

0 commit comments

Comments
 (0)