comparison proxy_cache.t @ 424:e402c5ed57eb

Tests: caching of empty responses on HEAD requests. There are already two independent patches which used to break this case, it's time to add some tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 03 Jul 2014 05:57:44 +0400
parents 44c42894fdfd
children 071e8941e3bf
comparison
equal deleted inserted replaced
423:1ac74b568503 424:e402c5ed57eb
21 select STDERR; $| = 1; 21 select STDERR; $| = 1;
22 select STDOUT; $| = 1; 22 select STDOUT; $| = 1;
23 23
24 plan(skip_all => 'win32') if $^O eq 'MSWin32'; 24 plan(skip_all => 'win32') if $^O eq 'MSWin32';
25 25
26 my $t = Test::Nginx->new()->has(qw/http proxy cache gzip/)->plan(11) 26 my $t = Test::Nginx->new()->has(qw/http proxy cache gzip/)->plan(14)
27 ->write_file_expand('nginx.conf', <<'EOF'); 27 ->write_file_expand('nginx.conf', <<'EOF');
28 28
29 %%TEST_GLOBALS%% 29 %%TEST_GLOBALS%%
30 30
31 daemon off; 31 daemon off;
57 57
58 proxy_cache_min_uses 1; 58 proxy_cache_min_uses 1;
59 59
60 proxy_cache_use_stale error timeout invalid_header http_500 60 proxy_cache_use_stale error timeout invalid_header http_500
61 http_404; 61 http_404;
62
63 add_header X-Cache-Status $upstream_cache_status;
62 } 64 }
63 } 65 }
64 server { 66 server {
65 listen 127.0.0.1:8081; 67 listen 127.0.0.1:8081;
66 server_name localhost; 68 server_name localhost;
87 89
88 unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head request'); 90 unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head request');
89 like(http_get('/t2.html'), qr/SEE-THIS/, 'get after head'); 91 like(http_get('/t2.html'), qr/SEE-THIS/, 'get after head');
90 unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head after get'); 92 unlike(http_head('/t2.html'), qr/SEE-THIS/, 'head after get');
91 93
94 like(http_head('/empty.html?head'), qr/MISS/, 'empty head first');
95 like(http_head('/empty.html?head'), qr/HIT/, 'empty head second');
96
92 like(http_get_range('/t.html', 'Range: bytes=4-'), qr/^THIS/m, 'cached range'); 97 like(http_get_range('/t.html', 'Range: bytes=4-'), qr/^THIS/m, 'cached range');
93 like(http_get_range('/t.html', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms, 98 like(http_get_range('/t.html', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms,
94 'cached multipart range'); 99 'cached multipart range');
95 100
96 like(http_get('/empty.html'), qr/HTTP/, 'empty get first'); 101 like(http_get('/empty.html'), qr/MISS/, 'empty get first');
97 like(http_get('/empty.html'), qr/HTTP/, 'empty get second'); 102 like(http_get('/empty.html'), qr/HIT/, 'empty get second');
98 103
99 select(undef, undef, undef, 1.1); 104 select(undef, undef, undef, 1.1);
100 unlink $t->testdir() . '/t.html'; 105 unlink $t->testdir() . '/t.html';
101 like(http_gzip_request('/t.html'), 106 like(http_gzip_request('/t.html'),
102 qr/HTTP.*1c\x0d\x0a.{28}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s, 107 qr/HTTP.*1c\x0d\x0a.{28}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s,
104 109
105 unlink $t->testdir() . '/empty.html'; 110 unlink $t->testdir() . '/empty.html';
106 like(http_gzip_request('/empty.html'), 111 like(http_gzip_request('/empty.html'),
107 qr/HTTP.*14\x0d\x0a.{20}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s, 112 qr/HTTP.*14\x0d\x0a.{20}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s,
108 'empty get stale'); 113 'empty get stale');
114
115 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts');
109 116
110 ############################################################################### 117 ###############################################################################
111 118
112 sub http_get_range { 119 sub http_get_range {
113 my ($url, $extra) = @_; 120 my ($url, $extra) = @_;