Mercurial > hg > nginx-tests
comparison proxy_cache_revalidate.t @ 413:f620d9529ed6
Tests: cache revalidate tests with ETag.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 20 Jun 2014 18:07:29 +0400 |
parents | 847ea345becb |
children | 43e05ac6c23c |
comparison
equal
deleted
inserted
replaced
412:995f3476202e | 413:f620d9529ed6 |
---|---|
57 } | 57 } |
58 | 58 |
59 server { | 59 server { |
60 listen 127.0.0.1:8081; | 60 listen 127.0.0.1:8081; |
61 server_name localhost; | 61 server_name localhost; |
62 | |
63 location / { } | |
64 location /etag/ { | |
65 proxy_pass http://127.0.0.1:8081/; | |
66 proxy_hide_header Last-Modified; | |
67 } | |
62 } | 68 } |
63 } | 69 } |
64 | 70 |
65 EOF | 71 EOF |
66 | 72 |
67 $t->write_file('t', 'SEE-THIS'); | 73 $t->write_file('t', 'SEE-THIS'); |
68 $t->write_file('t2', 'SEE-THIS'); | 74 $t->write_file('t2', 'SEE-THIS'); |
69 | 75 |
70 $t->run()->plan(9); | 76 $t->run()->plan(17); |
71 | 77 |
72 ############################################################################### | 78 ############################################################################### |
73 | 79 |
74 # request documents and make sure they are cached | 80 # request documents and make sure they are cached |
75 | 81 |
77 like(http_get('/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'request cached'); | 83 like(http_get('/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'request cached'); |
78 | 84 |
79 like(http_get('/t2'), qr/X-Cache-Status: MISS.*SEE/ms, '2nd request'); | 85 like(http_get('/t2'), qr/X-Cache-Status: MISS.*SEE/ms, '2nd request'); |
80 like(http_get('/t2'), qr/X-Cache-Status: HIT.*SEE/ms, '2nd request cached'); | 86 like(http_get('/t2'), qr/X-Cache-Status: HIT.*SEE/ms, '2nd request cached'); |
81 | 87 |
88 like(http_get('/etag/t'), qr/X-Cache-Status: MISS.*SEE/ms, 'etag'); | |
89 like(http_get('/etag/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag cached'); | |
90 | |
91 like(http_get('/etag/t2'), qr/X-Cache-Status: MISS.*SEE/ms, 'etag2'); | |
92 like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag2 cached'); | |
93 | |
82 # wait for a while for cached responses to expire | 94 # wait for a while for cached responses to expire |
83 | 95 |
84 select undef, undef, undef, 2.5; | 96 select undef, undef, undef, 2.5; |
85 | 97 |
86 # 1st document isn't modified, and should be revalidated on first request | 98 # 1st document isn't modified, and should be revalidated on first request |
87 # (a 304 status code will appear in backend's logs), then cached again | 99 # (a 304 status code will appear in backend's logs), then cached again |
88 | 100 |
89 like(http_get('/t'), qr/X-Cache-Status: REVALIDATED.*SEE/ms, 'revalidated'); | 101 like(http_get('/t'), qr/X-Cache-Status: REVALIDATED.*SEE/ms, 'revalidated'); |
90 like(http_get('/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'request cached'); | 102 like(http_get('/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'cached again'); |
91 | 103 |
92 select undef, undef, undef, 0.1; | 104 select undef, undef, undef, 0.1; |
93 like(read_file($t->testdir() . '/access.log'), qr/ 304 /, 'not modified'); | 105 like(read_file($t->testdir() . '/access.log'), qr/ 304 /, 'not modified'); |
94 | 106 |
95 # 2nd document is recreated with a new content | 107 # 2nd document is recreated with a new content |
96 | 108 |
97 $t->write_file('t2', 'NEW'); | 109 $t->write_file('t2', 'NEW'); |
98 like(http_get('/t2'), qr/X-Cache-Status: EXPIRED.*NEW/ms, 'revalidate failed'); | 110 like(http_get('/t2'), qr/X-Cache-Status: EXPIRED.*NEW/ms, 'revalidate failed'); |
99 like(http_get('/t2'), qr/X-Cache-Status: HIT.*NEW/ms, 'new response cached'); | 111 like(http_get('/t2'), qr/X-Cache-Status: HIT.*NEW/ms, 'new response cached'); |
112 | |
113 # the same for etag: | |
114 # 1st document isn't modified | |
115 # 2nd document is recreated | |
116 | |
117 TODO: { | |
118 local $TODO = 'not yet'; | |
119 | |
120 like(http_get('/etag/t'), qr/X-Cache-Status: REVALIDATED.*SEE/ms, | |
121 'etag revalidated'); | |
122 | |
123 } | |
124 | |
125 like(http_get('/etag/t'), qr/X-Cache-Status: HIT.*SEE/ms, | |
126 'etag cached again'); | |
127 like(http_get('/etag/t2'), qr/X-Cache-Status: EXPIRED.*NEW/ms, | |
128 'etag2 revalidate failed'); | |
129 like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*NEW/ms, | |
130 'etag2 new response cached'); | |
100 | 131 |
101 ############################################################################### | 132 ############################################################################### |
102 | 133 |
103 sub read_file { | 134 sub read_file { |
104 my ($file) = @_; | 135 my ($file) = @_; |