changeset 140:3f246a1be2b0

Tests: unfinished responses shouldn't be cached.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 19 Jul 2010 04:55:06 +0400
parents 8b62dd9b8615
children 1e1975cd25ef
files proxy-cache.t
diffstat 1 files changed, 46 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/proxy-cache.t
+++ b/proxy-cache.t
@@ -21,7 +21,7 @@ use Test::Nginx qw/ :DEFAULT :gzip /;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http proxy cache gzip/)->plan(9)
+my $t = Test::Nginx->new()->has(qw/http proxy cache gzip/)->plan(10)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -59,6 +59,11 @@ http {
             proxy_cache_use_stale  error timeout invalid_header http_500
                                    http_404;
         }
+
+        location /fake/ {
+            proxy_pass    http://127.0.0.1:8082;
+            proxy_cache   NAME;
+        }
     }
     server {
         listen       127.0.0.1:8081;
@@ -74,6 +79,7 @@ EOF
 $t->write_file('t.html', 'SEE-THIS');
 $t->write_file('t2.html', 'SEE-THIS');
 $t->write_file('empty.html', '');
+$t->run_daemon(\&http_fake_daemon);
 $t->run();
 
 ###############################################################################
@@ -109,4 +115,43 @@ like(http_gzip_request('/empty.html'),
 	'empty get stale');
 }
 
+{
+local $TODO = 'patch pending';
+
+http_get('/fake/unfinished');
+like(http_get('/fake/unfinished'), qr/unfinished 2/, 'unfinished not cached');
+}
+
 ###############################################################################
+
+sub http_fake_daemon {
+	my $server = IO::Socket::INET->new(
+		Proto => 'tcp',
+		LocalAddr => '127.0.0.1:8082',
+		Listen => 5,
+		Reuse => 1
+	)
+		or die "Can't create listening socket: $!\n";
+
+	my $num = 0;
+
+	while (my $client = $server->accept()) {
+		$client->autoflush(1);
+
+		while (<$client>) {
+			last if (/^\x0d?\x0a?$/);
+		}
+
+		$num++;
+		print $client <<"EOF";
+HTTP/1.1 200 OK
+Content-Length: 100
+Cache-Control: max-age=300
+Connection: close
+
+unfinished $num
+EOF
+	}
+}
+
+###############################################################################