changeset 413:f620d9529ed6

Tests: cache revalidate tests with ETag.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 20 Jun 2014 18:07:29 +0400
parents 995f3476202e
children 068d020a8f85
files proxy_cache_revalidate.t
diffstat 1 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/proxy_cache_revalidate.t
+++ b/proxy_cache_revalidate.t
@@ -59,6 +59,12 @@ http {
     server {
         listen       127.0.0.1:8081;
         server_name  localhost;
+
+        location / { }
+        location /etag/ {
+            proxy_pass http://127.0.0.1:8081/;
+            proxy_hide_header Last-Modified;
+        }
     }
 }
 
@@ -67,7 +73,7 @@ EOF
 $t->write_file('t', 'SEE-THIS');
 $t->write_file('t2', 'SEE-THIS');
 
-$t->run()->plan(9);
+$t->run()->plan(17);
 
 ###############################################################################
 
@@ -79,6 +85,12 @@ like(http_get('/t'), qr/X-Cache-Status: 
 like(http_get('/t2'), qr/X-Cache-Status: MISS.*SEE/ms, '2nd request');
 like(http_get('/t2'), qr/X-Cache-Status: HIT.*SEE/ms, '2nd request cached');
 
+like(http_get('/etag/t'), qr/X-Cache-Status: MISS.*SEE/ms, 'etag');
+like(http_get('/etag/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag cached');
+
+like(http_get('/etag/t2'), qr/X-Cache-Status: MISS.*SEE/ms, 'etag2');
+like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag2 cached');
+
 # wait for a while for cached responses to expire
 
 select undef, undef, undef, 2.5;
@@ -87,7 +99,7 @@ select undef, undef, undef, 2.5;
 # (a 304 status code will appear in backend's logs), then cached again
 
 like(http_get('/t'), qr/X-Cache-Status: REVALIDATED.*SEE/ms, 'revalidated');
-like(http_get('/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'request cached');
+like(http_get('/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'cached again');
 
 select undef, undef, undef, 0.1;
 like(read_file($t->testdir() . '/access.log'), qr/ 304 /, 'not modified');
@@ -98,6 +110,25 @@ like(read_file($t->testdir() . '/access.
 like(http_get('/t2'), qr/X-Cache-Status: EXPIRED.*NEW/ms, 'revalidate failed');
 like(http_get('/t2'), qr/X-Cache-Status: HIT.*NEW/ms, 'new response cached');
 
+# the same for etag:
+# 1st document isn't modified
+# 2nd document is recreated
+
+TODO: {
+local $TODO = 'not yet';
+
+like(http_get('/etag/t'), qr/X-Cache-Status: REVALIDATED.*SEE/ms,
+	'etag revalidated');
+
+}
+
+like(http_get('/etag/t'), qr/X-Cache-Status: HIT.*SEE/ms,
+	'etag cached again');
+like(http_get('/etag/t2'), qr/X-Cache-Status: EXPIRED.*NEW/ms,
+	'etag2 revalidate failed');
+like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*NEW/ms,
+	'etag2 new response cached');
+
 ###############################################################################
 
 sub read_file {