Tests: improved proxy_next_upstream tests. A new test added to make sure that all bad backends are tried once.
diff --git a/proxy_next_upstream.t b/proxy_next_upstream.t index ef376dc..1808093 100644 --- a/proxy_next_upstream.t +++ b/proxy_next_upstream.t
@@ -21,7 +21,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(6); +my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(7); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -40,6 +40,11 @@ server 127.0.0.1:8082; } + upstream u2 { + server 127.0.0.1:8081; + server 127.0.0.1:8082; + } + server { listen 127.0.0.1:8080; server_name localhost; @@ -48,6 +53,17 @@ proxy_pass http://u; proxy_next_upstream http_500 http_404; } + + location /all/ { + proxy_pass http://u2; + proxy_next_upstream http_500 http_404; + error_page 404 /all/404; + proxy_intercept_errors on; + } + + location /all/404 { + return 200 "$upstream_addr\n"; + } } server { @@ -63,6 +79,10 @@ location /500 { return 500; } + + location /all/ { + return 404; + } } server { @@ -72,6 +92,10 @@ location / { return 200 "TEST-OK-IF-YOU-SEE-THIS\n"; } + + location /all/ { + return 404; + } } } @@ -101,4 +125,10 @@ unlike(http_get('/ok') . http_get('/ok'), qr/AND-THIS/, 'down after 500'); +# make sure all backends are tried once + +like(http_get('/all/rr'), + qr/^127.0.0.1:808(1, 127.0.0.1:8082|2, 127.0.0.1:8081)$/mi, + 'all tried once'); + ###############################################################################