# HG changeset patch # User Maxim Dounin # Date 1403273249 -14400 # Node ID f620d9529ed6b76959a694c27b24ba01de4787af # Parent 995f3476202e4d5b442f295a189cecffa2da6f92 Tests: cache revalidate tests with ETag. diff --git a/proxy_cache_revalidate.t b/proxy_cache_revalidate.t --- 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 {