comparison proxy_cache_use_stale.t @ 1587:17b227c271a2

Tests: 4xx and 5xx codes with stale-while-revalidate. Now these codes do not fall under stale-if-error (enabled by stale-while-revalidate).
author Roman Arutyunyan <arut@nginx.com>
date Fri, 14 Aug 2020 13:32:27 +0300
parents 144c6ce732e4
children 5ac6efbe5552
comparison
equal deleted inserted replaced
1586:e145509cc6eb 1587:17b227c271a2
149 $t->write_file('ssi.html', 'xxx <!--#include virtual="/t9.html" --> xxx'); 149 $t->write_file('ssi.html', 'xxx <!--#include virtual="/t9.html" --> xxx');
150 $t->write_file('escape.html', 'SEE-THIS'); 150 $t->write_file('escape.html', 'SEE-THIS');
151 $t->write_file('escape html', 'SEE-THIS'); 151 $t->write_file('escape html', 'SEE-THIS');
152 $t->write_file('regexp.html', 'SEE-THIS'); 152 $t->write_file('regexp.html', 'SEE-THIS');
153 153
154 $t->run()->plan(35); 154 $t->run()->plan(36);
155 155
156 ############################################################################### 156 ###############################################################################
157 157
158 like(get('/t.html', 'max-age=1, stale-if-error=5'), qr/MISS/, 'stale-if-error'); 158 like(get('/t.html', 'max-age=1, stale-if-error=5'), qr/MISS/, 'stale-if-error');
159 like(http_get('/t.html?e=1'), qr/HIT/, 's-i-e - cached'); 159 like(http_get('/t.html?e=1'), qr/HIT/, 's-i-e - cached');
169 get('/t6.html', 'max-age=1, stale-while-revalidate=4'); 169 get('/t6.html', 'max-age=1, stale-while-revalidate=4');
170 get('/t7.html', 'max-age=1, stale-while-revalidate=10'); 170 get('/t7.html', 'max-age=1, stale-while-revalidate=10');
171 http_get('/ssi.html'); 171 http_get('/ssi.html');
172 get('/updating/t.html', 'max-age=1'); 172 get('/updating/t.html', 'max-age=1');
173 get('/updating/t2.html', 'max-age=1, stale-while-revalidate=2'); 173 get('/updating/t2.html', 'max-age=1, stale-while-revalidate=2');
174 get('/updating/tt.html', 'max-age=1, stale-if-error=5');
174 get('/t8.html', 'stale-while-revalidate=10'); 175 get('/t8.html', 'stale-while-revalidate=10');
175 get('/escape.htm%6C', 'max-age=1, stale-while-revalidate=10'); 176 get('/escape.htm%6C', 'max-age=1, stale-while-revalidate=10');
176 get('/escape html', 'max-age=1, stale-while-revalidate=10'); 177 get('/escape html', 'max-age=1, stale-while-revalidate=10');
177 get('/regexp.html', 'max-age=1, stale-while-revalidate=10'); 178 get('/regexp.html', 'max-age=1, stale-while-revalidate=10');
178 179
179 sleep 2; 180 sleep 2;
180 181
181 like(http_get('/t.html?e=1'), qr/STALE/, 's-i-e - stale'); 182 TODO: {
182 like(http_get('/tt.html?e=1'), qr/STALE/, 's-i-e - stale 2'); 183 local $TODO = 'not yet' unless $t->has_version('1.19.3');
184
185 # stale 5xx response is ignored since 1.19.3,
186 # "proxy_cache_use_stale updating;" allows to get it still
187
188 like(http_get('/t.html?e=1'), qr/ 500 /, 's-i-e - stale 5xx ignore');
189 like(http_get('/tt.html?e=1'), qr/ 500 /, 's-i-e - stale 5xx ignore 2');
190
191 }
192
193 like(http_get('/updating/tt.html'), qr/STALE/, 's-i-e - stale 5xx updating');
183 like(http_get('/t.html'), qr/REVALIDATED/, 's-i-e - revalidated'); 194 like(http_get('/t.html'), qr/REVALIDATED/, 's-i-e - revalidated');
184 195
185 like(http_get('/t2.html?e=1'), qr/STALE/, 's-w-r - revalidate error'); 196 like(http_get('/t2.html?e=1'), qr/STALE/, 's-w-r - revalidate error');
186 like(http_get('/t2.html'), qr/STALE/, 's-w-r - stale while revalidate'); 197 like(http_get('/t2.html'), qr/STALE/, 's-w-r - stale while revalidate');
187 like(http_get('/t2.html'), qr/HIT/, 's-w-r - revalidated'); 198 like(http_get('/t2.html'), qr/HIT/, 's-w-r - revalidated');
188 199
189 like(get('/t4.html', 'max-age=1, stale-while-revalidate=2'), qr/STALE/, 200 like(get('/t4.html', 'max-age=1, stale-while-revalidate=2'), qr/STALE/,
190 's-w-r - unconditional revalidate'); 201 's-w-r - unconditional revalidate');
191 like(http_get('/t4.html'), qr/HIT/, 's-w-r - unconditional revalidated'); 202 like(http_get('/t4.html'), qr/HIT/, 's-w-r - unconditional revalidated');
192 203
193 like(http_get('/t5.html?e=1'), qr/STALE/, 204 TODO: {
205 local $TODO = 'not yet' unless $t->has_version('1.19.3');
206
207 like(http_get('/t5.html?e=1'), qr/ 500 /,
194 's-w-r - foreground revalidate error'); 208 's-w-r - foreground revalidate error');
209
210 }
211
195 like(http_get('/t5.html'), qr/REVALIDATED/, 's-w-r - foreground revalidated'); 212 like(http_get('/t5.html'), qr/REVALIDATED/, 's-w-r - foreground revalidated');
196 213
197 # proxy_pass to regular expression with named and positional captures 214 # proxy_pass to regular expression with named and positional captures
198 215
199 like(http_get('/regexp.html'), qr/STALE/, 's-w-r - regexp background update'); 216 like(http_get('/regexp.html'), qr/STALE/, 's-w-r - regexp background update');