[PATCH 3 of 3] Tests: add propagate_connection_close tests

Shawn J. Goff shawgoff at amazon.com
Sat Jan 3 00:54:14 UTC 2015


# HG changeset patch
# User Shawn J. Goff <shawgoff at amazon.com>
# Date 1419637716 28800
# Node ID fdf48082ebc389a967b9d4064f1b8cc447427c78
# Parent  7e0cf8051ecb5c358dfd0bea94aa0aefa744ee29
Tests: add propagate_connection_close tests.

propagate_connection_close causes nginx to close the downstream connection if
the upstream returns a "Connection: close" header.

This change adds tests for the existing/default behavior as well as enabled and
disabled. For each setting, it does two tests: one that will cause the upstream
server to close the connection and one that will cause the upstream server to
keep the connection alive.

Conflicts:

        lib/Test/Nginx.pm

diff -r 7e0cf8051ecb -r fdf48082ebc3 upstream.t
--- a/upstream.t        Fri Dec 26 16:03:33 2014 -0800
+++ b/upstream.t        Fri Dec 26 15:48:36 2014 -0800
@@ -21,7 +21,7 @@
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(3);
+my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(9);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -55,6 +55,29 @@
         location /close2 {
             proxy_pass http://u2;
         }
+
+        location /close_pcc_default {
+            proxy_pass http://u2;
+        }
+        location /keep-alive_pcc_default {
+            proxy_pass http://u2;
+        }
+        location /close_pcc_on {
+            proxy_pass http://u2;
+            propagate_connection_close on;
+        }
+        location /keep-alive_pcc_on {
+            proxy_pass http://u2;
+            propagate_connection_close on;
+        }
+        location /close_pcc_off {
+            proxy_pass http://u2;
+            propagate_connection_close off;
+        }
+        location /keep-alive_pcc_off {
+            proxy_pass http://u2;
+            propagate_connection_close off;
+        }
     }
 }
 
@@ -77,6 +100,18 @@
 
 is(many('/close', 30), '8081: 6, 8082: 24', 'failures');
 
+# test propagate_connection_close=default behavior
+like(http_get_v11('/keep-alive_pcc_default'), qr/Connection: keep-alive/, 'pcc keep-alive default');
+like(http_get_v11('/close_pcc_default'), qr/Connection: keep-alive/, 'pcc close default');
+
+# test propagate_connection_close=on behavior
+like(http_get_v11('/keep-alive_pcc_on'), qr/Connection: keep-alive/, 'pcc keep-alive on');
+like(http_get_v11('/close_pcc_on'), qr/Connection: close/, 'pcc close on');
+
+# test propagate_connection_close=off behavior
+like(http_get_v11('/keep-alive_pcc_off'), qr/Connection: keep-alive/, 'pcc keep-alive off');
+like(http_get_v11('/close_pcc_off'), qr/Connection: keep-alive/, 'pcc close off');
+
 SKIP: {
 skip 'long test', 1 unless $ENV{TEST_NGINX_UNSAFE};
 
@@ -129,6 +164,7 @@
 
                my $headers = '';
                my $uri = '';
+               my $connection_header = 'close';
 
                while (<$client>) {
                        $headers .= $_;
@@ -141,9 +177,13 @@
                        next;
                }
 
+               if ($uri =~ 'keep-alive') {
+                       $connection_header = 'keep-alive'
+               }
+
                print $client <<EOF;
 HTTP/1.1 200 OK
-Connection: close
+Connection: $connection_header
 X-Port: $port
 
 OK



More information about the nginx-devel mailing list