[nginx-tests] Tests: stale-if-error with "proxy_next_upstream ht...

Maxim Dounin mdounin at mdounin.ru
Sat Jan 31 06:37:24 UTC 2026


details:   http://freenginx.org/hg/nginx-tests/rev/cccd744b9159
branches:  
changeset: 2041:cccd744b9159
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Sat Jan 31 09:27:25 2026 +0300
description:
Tests: stale-if-error with "proxy_next_upstream http_500".

diffstat:

 proxy_cache_use_stale.t |  22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diffs (58 lines):

diff --git a/proxy_cache_use_stale.t b/proxy_cache_use_stale.t
--- a/proxy_cache_use_stale.t
+++ b/proxy_cache_use_stale.t
@@ -94,6 +94,12 @@ http {
                 proxy_cache_use_stale  updating;
             }
 
+            location /next/ {
+                proxy_pass    http://127.0.0.1:8081/;
+
+                proxy_next_upstream  http_500;
+            }
+
             location /t7.html {
                 proxy_pass    http://127.0.0.1:8081;
 
@@ -150,7 +156,7 @@ EOF
 $t->write_file('escape.html', 'SEE-THIS');
 $t->write_file('regexp.html', 'SEE-THIS');
 
-$t->run()->plan(34);
+$t->run()->plan(35);
 
 ###############################################################################
 
@@ -171,20 +177,30 @@ http_get('/ssi.html');
 get('/updating/t.html', 'max-age=1');
 get('/updating/t2.html', 'max-age=1, stale-while-revalidate=2');
 get('/updating/tt.html', 'max-age=1, stale-if-error=5');
+get('/next/tt.html', 'max-age=1, stale-if-error=5');
 get('/t8.html', 'stale-while-revalidate=20');
 get('/escape.htm%6C', 'max-age=1, stale-while-revalidate=20');
 get('/regexp.html', 'max-age=1, stale-while-revalidate=20');
 
 sleep 2;
 
-# stale 5xx response is ignored since 1.19.3,
-# "proxy_cache_use_stale updating;" allows to get it still
+# if an upstream returns a valid HTTP response, stale cached response
+# with "stale-if-error=..." is only used if the status code is listed
+# in proxy_next_upstream (1.29.5) or using stale responses is enabled
+# with proxy_cache_use_stale
 
 like(http_get('/t.html?e=1'), qr/ 500 /, 's-i-e - stale 5xx ignore');
 like(http_get('/tt.html?e=1'), qr/ 500 /, 's-i-e - stale 5xx ignore 2');
 like(http_get('/updating/tt.html'), qr/STALE/, 's-i-e - stale 5xx updating');
 like(http_get('/t.html'), qr/REVALIDATED/, 's-i-e - revalidated');
 
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.29.5');
+
+like(http_get('/next/tt.html?e=1'), qr/STALE/, 's-i-e - stale 5xx next');
+
+}
+
 like(http_get('/t2.html?e=1'), qr/STALE/, 's-w-r - revalidate error');
 like(http_get('/t2.html'), qr/STALE/, 's-w-r - stale while revalidate');
 like(http_get('/t2.html'), qr/HIT/, 's-w-r - revalidated');


More information about the nginx-devel mailing list