comparison http_keepalive.t @ 1667:bdebd63dbab3

Tests: keepalive_time tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 08 Apr 2021 12:59:11 +0300
parents a40f94bc92d4
children 0c1bd4c23c95
comparison
equal deleted inserted replaced
1666:9d4c88e5c183 1667:bdebd63dbab3
22 ############################################################################### 22 ###############################################################################
23 23
24 select STDERR; $| = 1; 24 select STDERR; $| = 1;
25 select STDOUT; $| = 1; 25 select STDOUT; $| = 1;
26 26
27 my $t = Test::Nginx->new()->has(qw/http/)->plan(16) 27 my $t = Test::Nginx->new()->has(qw/http/)
28 ->write_file_expand('nginx.conf', <<'EOF'); 28 ->write_file_expand('nginx.conf', <<'EOF');
29 29
30 %%TEST_GLOBALS%% 30 %%TEST_GLOBALS%%
31 31
32 daemon off; 32 daemon off;
53 location /r { 53 location /r {
54 keepalive_requests 4; 54 keepalive_requests 4;
55 keepalive_timeout 30s; 55 keepalive_timeout 30s;
56 } 56 }
57 57
58 location /time {
59 keepalive_requests 100;
60 keepalive_timeout 75s;
61 keepalive_time 1s;
62 }
63
58 location /safari { 64 location /safari {
59 keepalive_disable safari; 65 keepalive_disable safari;
60 } 66 }
61 67
62 location /none { 68 location /none {
71 77
72 EOF 78 EOF
73 79
74 $t->write_file('index.html', ''); 80 $t->write_file('index.html', '');
75 $t->write_file('r', ''); 81 $t->write_file('r', '');
82 $t->write_file('time', '');
76 $t->write_file('safari', ''); 83 $t->write_file('safari', '');
77 $t->write_file('none', ''); 84 $t->write_file('none', '');
78 $t->write_file('zero', ''); 85 $t->write_file('zero', '');
79 $t->run(); 86 $t->try_run('no keepalive_time')->plan(20);
80 87
81 ############################################################################### 88 ###############################################################################
82 89
83 # keepalive_requests 90 # keepalive_requests
84 91
108 is(count_keepalive($r), 1, 'keepalive timeout request'); 115 is(count_keepalive($r), 1, 'keepalive timeout request');
109 like($r, qr/Keep-Alive: timeout=9/, 'keepalive timeout header'); 116 like($r, qr/Keep-Alive: timeout=9/, 'keepalive timeout header');
110 117
111 like(http_keepalive('/zero'), qr/Connection: close/, 'keepalive timeout 0'); 118 like(http_keepalive('/zero'), qr/Connection: close/, 'keepalive timeout 0');
112 119
120 # keepalive_time
121
122 $r = http_keepalive('/time', req => 3);
123 is(() = $r =~ /(200 OK)/g, 3, 'keepalive time requests');
124 unlike($r, qr/Connection: close/, 'keepalive time connection');
125
126 $r = http_keepalive('/time', req => 3, sleep => 1.1);
127 is(() = $r =~ /(200 OK)/g, 2, 'keepalive time limit requests');
128 like($r, qr/Connection: close/, 'keepalive time limit connection');
129
113 # cancel keepalive on EOF while discarding body 130 # cancel keepalive on EOF while discarding body
114 131
115 my $s = http(<<EOF, start => 1); 132 my $s = http(<<EOF, start => 1);
116 POST /r HTTP/1.1 133 POST /r HTTP/1.1
117 Host: localhost 134 Host: localhost