comparison proxy_cache_revalidate.t @ 531:679a7669ee71

Tests: no revalidation of a 404 cache entry.
author Sergey Kandaurov <pluknet@nginx.com>
date Sat, 28 Feb 2015 15:17:48 +0300
parents a61571a5f8df
children 907e89fba9c3
comparison
equal deleted inserted replaced
530:a61571a5f8df 531:679a7669ee71
47 47
48 location / { 48 location / {
49 proxy_pass http://127.0.0.1:8081; 49 proxy_pass http://127.0.0.1:8081;
50 proxy_cache one; 50 proxy_cache one;
51 51
52 proxy_cache_valid 200 1s; 52 proxy_cache_valid 200 404 1s;
53 53
54 add_header X-Cache-Status $upstream_cache_status; 54 add_header X-Cache-Status $upstream_cache_status;
55 } 55 }
56 } 56 }
57 57
73 } 73 }
74 } 74 }
75 75
76 EOF 76 EOF
77 77
78 my $d = $t->testdir();
79
78 $t->write_file('t', 'SEE-THIS'); 80 $t->write_file('t', 'SEE-THIS');
79 $t->write_file('t2', 'SEE-THIS'); 81 $t->write_file('t2', 'SEE-THIS');
82 $t->write_file('t3', 'SEE-THIS');
80 83
81 $t->run()->plan(20); 84 $t->run()->plan(23);
82 85
83 ############################################################################### 86 ###############################################################################
84 87
85 # request documents and make sure they are cached 88 # request documents and make sure they are cached
86 89
97 like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag2 cached'); 100 like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag2 cached');
98 101
99 like(http_get('/201'), qr/X-Cache-Status: MISS/, 'other status'); 102 like(http_get('/201'), qr/X-Cache-Status: MISS/, 'other status');
100 like(http_get('/201'), qr/X-Cache-Status: HIT/, 'other status cached'); 103 like(http_get('/201'), qr/X-Cache-Status: HIT/, 'other status cached');
101 104
105 like(http_get('/t3'), qr/SEE/, 'cache before 404');
106
102 # wait for a while for cached responses to expire 107 # wait for a while for cached responses to expire
103 108
104 select undef, undef, undef, 2.5; 109 select undef, undef, undef, 2.5;
105 110
106 # 1st document isn't modified, and should be revalidated on first request 111 # 1st document isn't modified, and should be revalidated on first request
107 # (a 304 status code will appear in backend's logs), then cached again 112 # (a 304 status code will appear in backend's logs), then cached again
108 113
109 like(http_get('/t'), qr/X-Cache-Status: REVALIDATED.*SEE/ms, 'revalidated'); 114 like(http_get('/t'), qr/X-Cache-Status: REVALIDATED.*SEE/ms, 'revalidated');
110 like(http_get('/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'cached again'); 115 like(http_get('/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'cached again');
116
117 rename("$d/t3", "$d/t3_moved");
118
119 like(http_get('/t3'), qr/ 404 /, 'cache 404 response');
111 120
112 select undef, undef, undef, 0.1; 121 select undef, undef, undef, 0.1;
113 like($t->read_file('access.log'), qr/ 304 /, 'not modified'); 122 like($t->read_file('access.log'), qr/ 304 /, 'not modified');
114 123
115 # 2nd document is recreated with a new content 124 # 2nd document is recreated with a new content
143 # the Last-Modified header when storing non-200/206 in cache; 152 # the Last-Modified header when storing non-200/206 in cache;
144 # 1573fc7875fa in 1.7.9 effectively turned it back. 153 # 1573fc7875fa in 1.7.9 effectively turned it back.
145 154
146 unlike(http_get('/201'), qr/X-If-Modified/, 'other status no revalidation'); 155 unlike(http_get('/201'), qr/X-If-Modified/, 'other status no revalidation');
147 156
157 # wait for a while for a cached 404 response to expire
158
159 select undef, undef, undef, 2.5;
160
161 # check that conditional requests are not used to revalidate 404 response
162
163 # before fd283aa92e04 introduced in 1.7.7, this test passed by chance because
164 # of the If-Modified-Since header that was sent with Epoch in revalidation
165 # of responses cached without the Last-Modified header;
166 # fd283aa92e04 leaved (an legitimate) successful revalidation of 404 by ETag
167 # (introduced by 44b9ab7752e3 in 1.7.3), which caused the test to fail;
168 # 1573fc7875fa in 1.7.9 changed to not revalidate non-200/206 responses but
169 # leaked Last-Modified and ETag into 404 inherited from stale 200/206 response;
170 # 174512857ccf in 1.7.11 fixed the leak and allowed the test to pass.
171
172 rename("$d/t3_moved", "$d/t3");
173
174 like(http_get('/t3'), qr/SEE/, 'no 404 revalidation after stale 200');
175
148 ############################################################################### 176 ###############################################################################