Mercurial > hg > nginx-tests
comparison proxy_cache.t @ 299:44c42894fdfd
Tests: move unfinished tests to a separate file.
Add more tests to catch unfinished chunked responses, as well as
proxy-only aspect of the problem (we shouldn't send final chunk if
we know the response isn't complete).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 11 Jun 2013 17:14:37 +0400 |
parents | 6fe0459b6668 |
children | e402c5ed57eb |
comparison
equal
deleted
inserted
replaced
298:e491290fe83a | 299:44c42894fdfd |
---|---|
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(12) | 26 my $t = Test::Nginx->new()->has(qw/http proxy cache gzip/)->plan(11) |
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; |
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 } | 62 } |
63 | |
64 location /fake/ { | |
65 proxy_pass http://127.0.0.1:8082; | |
66 proxy_cache NAME; | |
67 } | |
68 } | 63 } |
69 server { | 64 server { |
70 listen 127.0.0.1:8081; | 65 listen 127.0.0.1:8081; |
71 server_name localhost; | 66 server_name localhost; |
72 | 67 |
79 | 74 |
80 $t->write_file('t.html', 'SEE-THIS'); | 75 $t->write_file('t.html', 'SEE-THIS'); |
81 $t->write_file('t2.html', 'SEE-THIS'); | 76 $t->write_file('t2.html', 'SEE-THIS'); |
82 $t->write_file('empty.html', ''); | 77 $t->write_file('empty.html', ''); |
83 | 78 |
84 $t->run_daemon(\&http_fake_daemon); | 79 $t->run(); |
85 $t->run()->waitforsocket('127.0.0.1:8081'); | |
86 | 80 |
87 ############################################################################### | 81 ############################################################################### |
88 | 82 |
89 like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request'); | 83 like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request'); |
90 | 84 |
111 unlink $t->testdir() . '/empty.html'; | 105 unlink $t->testdir() . '/empty.html'; |
112 like(http_gzip_request('/empty.html'), | 106 like(http_gzip_request('/empty.html'), |
113 qr/HTTP.*14\x0d\x0a.{20}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s, | 107 qr/HTTP.*14\x0d\x0a.{20}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s, |
114 'empty get stale'); | 108 'empty get stale'); |
115 | 109 |
116 http_get('/fake/unfinished'); | |
117 like(http_get('/fake/unfinished'), qr/unfinished 2/, 'unfinished not cached'); | |
118 | |
119 ############################################################################### | 110 ############################################################################### |
120 | 111 |
121 sub http_get_range { | 112 sub http_get_range { |
122 my ($url, $extra) = @_; | 113 my ($url, $extra) = @_; |
123 return http(<<EOF); | 114 return http(<<EOF); |
128 | 119 |
129 EOF | 120 EOF |
130 } | 121 } |
131 | 122 |
132 ############################################################################### | 123 ############################################################################### |
133 | |
134 sub http_fake_daemon { | |
135 my $server = IO::Socket::INET->new( | |
136 Proto => 'tcp', | |
137 LocalAddr => '127.0.0.1:8082', | |
138 Listen => 5, | |
139 Reuse => 1 | |
140 ) | |
141 or die "Can't create listening socket: $!\n"; | |
142 | |
143 local $SIG{PIPE} = 'IGNORE'; | |
144 | |
145 my $num = 0; | |
146 | |
147 while (my $client = $server->accept()) { | |
148 $client->autoflush(1); | |
149 | |
150 while (<$client>) { | |
151 last if (/^\x0d?\x0a?$/); | |
152 } | |
153 | |
154 $num++; | |
155 print $client <<"EOF"; | |
156 HTTP/1.1 200 OK | |
157 Content-Length: 100 | |
158 Cache-Control: max-age=300 | |
159 Connection: close | |
160 | |
161 unfinished $num | |
162 EOF | |
163 } | |
164 } | |
165 | |
166 ############################################################################### |