# HG changeset patch # User Sergey Kandaurov # Date 1606911392 0 # Node ID da1325cb1c39498975f7c86e27766ff1b3f5ad39 # Parent 62a1667f60f848afd1228fb4f35304c52b134f5a Tests: added proxy_next_upstream test with "down". diff --git a/proxy_next_upstream.t b/proxy_next_upstream.t --- a/proxy_next_upstream.t +++ b/proxy_next_upstream.t @@ -21,7 +21,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(7); +my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(8); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -45,6 +45,11 @@ http { server 127.0.0.1:8082; } + upstream u3 { + server 127.0.0.1:8081; + server 127.0.0.1:8082 down; + } + server { listen 127.0.0.1:8080; server_name localhost; @@ -64,6 +69,11 @@ http { location /all/404 { return 200 "$upstream_addr\n"; } + + location /down { + proxy_pass http://u3; + proxy_next_upstream http_404; + } } server { @@ -133,4 +143,14 @@ like(http_get('/all/rr'), qr/^127.0.0.1:($p1, 127.0.0.1:$p2|$p2, 127.0.0.1:$p1)$/mi, 'all tried once'); +# make sure backend marked as down doesn't count towards "no live upstreams" +# after all backends are tried with http_404 + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.19.6'); + +like(http_get('/down/'), qr/Not Found/, 'all tried with down'); + +} + ############################################################################### diff --git a/stream_proxy_next_upstream.t b/stream_proxy_next_upstream.t --- a/stream_proxy_next_upstream.t +++ b/stream_proxy_next_upstream.t @@ -23,7 +23,7 @@ use Test::Nginx::Stream qw/ stream /; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/stream/)->plan(3); +my $t = Test::Nginx->new()->has(qw/stream/)->plan(5); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -48,6 +48,11 @@ stream { server 127.0.0.1:8085 backup; } + upstream u3 { + server 127.0.0.1:8083; + server 127.0.0.1:8085 down; + } + proxy_connect_timeout 2; server { @@ -68,6 +73,15 @@ stream { proxy_next_upstream on; proxy_next_upstream_tries 2; } + + log_format test "$upstream_addr"; + + server { + listen 127.0.0.1:8086; + proxy_pass u3; + proxy_next_upstream on; + access_log %%TESTDIR%%/test.log test; + } } EOF @@ -84,6 +98,20 @@ is(stream('127.0.0.1:' . port(8081))->io is(stream('127.0.0.1:' . port(8082))->io('.'), '', 'next tries'); +# make sure backend marked as down doesn't count towards "no live upstreams" + +is(stream('127.0.0.1:' . port(8086))->io('.'), '', 'next down'); + +$t->stop(); + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.19.6'); + +is($t->read_file('test.log'), '127.0.0.1:' . port(8083) . "\n", + 'next down log'); + +} + ############################################################################### sub stream_daemon {