diff t/memcached-keepalive.t @ 11:15530a464dba

Keepalive: don't cache invalid connections. 1. Remember failed status, since peer.free() may be called more than once. It's called twice if peer fails - once from ngx_http_upstream_next() with NGX_PEER_FAILED set, and then from ngx_http_upstream_finalize_request() without. 2. We shouldn't cache connection unless we aren't expecting anything from upstream. For memcached this means either 404 response or 200 response with all body read (body may not be read e.g. when serving HEAD request).
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 13 Nov 2008 19:36:23 +0300
parents bef88ba0b378
children 067ddc059ee0
line wrap: on
line diff
--- a/t/memcached-keepalive.t
+++ b/t/memcached-keepalive.t
@@ -20,7 +20,7 @@ select STDOUT; $| = 1;
 eval { require Cache::Memcached; };
 plain(skip_all => 'Cache::Memcached not installed') if $@;
 
-my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(10)
+my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(16)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 master_process off;
@@ -105,6 +105,7 @@ my $memd2 = Cache::Memcached->new(server
 
 $memd1->set('/', 'SEE-THIS');
 $memd2->set('/', 'SEE-THIS');
+$memd1->set('/big', 'X' x 1000000);
 
 my $total = $memd1->stats()->{total}->{total_connections};
 
@@ -119,6 +120,26 @@ like(http_get('/'), qr/SEE-THIS/, 'keepa
 is($memd1->stats()->{total}->{total_connections}, $total + 1,
 	'only one connection used');
 
+# Since nginx doesn't read all data from connection in some situations (head
+# requests, post_action, errors writing to client) we have to close such
+# connections.  Check if we really do close them.
+
+$total = $memd1->stats()->{total}->{total_connections};
+
+unlike(http_head('/'), qr/SEE-THIS/, 'head request');
+like(http_get('/'), qr/SEE-THIS/, 'get after head');
+
+is($memd1->stats()->{total}->{total_connections}, $total + 1,
+	'head request closes connection');
+
+$total = $memd1->stats()->{total}->{total_connections};
+
+unlike(http_head('/big'), qr/XXX/, 'big head');
+like(http_get('/'), qr/SEE-THIS/, 'get after big head');
+
+is($memd1->stats()->{total}->{total_connections}, $total + 1,
+	'big head request closes connection');
+
 # two backends with 'single' option - should establish only one connection
 
 $total = $memd1->stats()->{total}->{total_connections} +