changeset 1632:da1325cb1c39

Tests: added proxy_next_upstream test with "down".
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 02 Dec 2020 12:16:32 +0000
parents 62a1667f60f8
children d57c7877b618
files proxy_next_upstream.t stream_proxy_next_upstream.t
diffstat 2 files changed, 50 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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');
+
+}
+
 ###############################################################################
--- 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 {