Mercurial > hg > nginx-tests
annotate http_keepalive.t @ 1670:489484af31eb
Tests: adjusted keepalive_time test timeout.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 12 Apr 2021 12:12:18 +0300 |
parents | 0c1bd4c23c95 |
children | 5ac6efbe5552 |
rev | line source |
---|---|
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for http keepalive directives. |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 |
1667
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http/) |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 events { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 http { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 |
1663
bf69dcabb856
Tests: $sent_http_keep_alive tests (ticket #1850).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1509
diff
changeset
|
40 log_format test1 $sent_http_connection; |
bf69dcabb856
Tests: $sent_http_keep_alive tests (ticket #1850).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1509
diff
changeset
|
41 log_format test2 $sent_http_keep_alive; |
bf69dcabb856
Tests: $sent_http_keep_alive tests (ticket #1850).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1509
diff
changeset
|
42 access_log %%TESTDIR%%/test1.log test1 if=$arg_l; |
bf69dcabb856
Tests: $sent_http_keep_alive tests (ticket #1850).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1509
diff
changeset
|
43 access_log %%TESTDIR%%/test2.log test2 if=$arg_l; |
1509
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
44 |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 server { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 listen 127.0.0.1:8080; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 server_name localhost; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 keepalive_requests 2; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 keepalive_timeout 1 9; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 |
1668
0c1bd4c23c95
Tests: $connection_requests and $connection_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1667
diff
changeset
|
52 add_header X-Conn $connection_requests:$connection_time; |
0c1bd4c23c95
Tests: $connection_requests and $connection_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1667
diff
changeset
|
53 |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 location / { } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 location /r { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 keepalive_requests 4; |
1665
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
57 keepalive_timeout 30s; |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 |
1667
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
60 location /time { |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
61 keepalive_requests 100; |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
62 keepalive_timeout 75s; |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
63 keepalive_time 1s; |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
64 } |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
65 |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 location /safari { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 keepalive_disable safari; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 location /none { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 keepalive_disable none; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 location /zero { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 keepalive_timeout 0; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 EOF |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 $t->write_file('index.html', ''); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 $t->write_file('r', ''); |
1667
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
84 $t->write_file('time', ''); |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 $t->write_file('safari', ''); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 $t->write_file('none', ''); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 $t->write_file('zero', ''); |
1668
0c1bd4c23c95
Tests: $connection_requests and $connection_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1667
diff
changeset
|
88 $t->try_run('no keepalive_time')->plan(21); |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 ############################################################################### |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 # keepalive_requests |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 like(http_keepalive('/'), qr/Connection: keep-alive/, 'keepalive request'); |
1509
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
95 is(count_keepalive(http_keepalive('/?l=ok', req => 2)), 1, 'keepalive limit'); |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 is(count_keepalive(http_keepalive('/r', req => 3)), 3, 'keepalive merge'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 is(count_keepalive(http_keepalive('/r', req => 5)), 3, 'keepalive merge limit'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 # keepalive_disable |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
100 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
101 like(http_keepalive('/', method => 'POST', ua => "MSIE 5.0"), |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 qr/Connection: close/, 'keepalive disable msie6'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
103 like(http_keepalive('/', ua => "MSIE 5.0"), qr/Connection: keep-alive/, |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
104 'keepalive disable msie6 GET'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
105 like(http_keepalive('/', method => 'POST', ua => "MSIE 7.0"), |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
106 qr/Connection: keep-alive/, 'keepalive disable msie6 modern'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
107 like(http_keepalive('/', ua => "Mac OS X Safari/7534.48.3"), |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
108 qr/Connection: keep-alive/, 'keepalive disable msie6 safari'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
109 like(http_keepalive('/safari', ua => "Mac OS X Safari/7534.48.3"), |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
110 qr/Connection: close/, 'keepalive disable safari'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
111 like(http_keepalive('/none', method => 'POST', ua => "MSIE 5.0"), |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
112 qr/Connection: keep-alive/, 'keepalive disable none'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
113 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
114 # keepalive_timeout |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
115 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
116 my $r = http_keepalive('/', req => 2, sleep => 2.1); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
117 is(count_keepalive($r), 1, 'keepalive timeout request'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
118 like($r, qr/Keep-Alive: timeout=9/, 'keepalive timeout header'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
119 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
120 like(http_keepalive('/zero'), qr/Connection: close/, 'keepalive timeout 0'); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
121 |
1667
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
122 # keepalive_time |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
123 |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
124 $r = http_keepalive('/time', req => 3); |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
125 is(() = $r =~ /(200 OK)/g, 3, 'keepalive time requests'); |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
126 unlike($r, qr/Connection: close/, 'keepalive time connection'); |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
127 |
1670
489484af31eb
Tests: adjusted keepalive_time test timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1668
diff
changeset
|
128 $r = http_keepalive('/time', req => 3, sleep => 1.2); |
1667
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
129 is(() = $r =~ /(200 OK)/g, 2, 'keepalive time limit requests'); |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
130 like($r, qr/Connection: close/, 'keepalive time limit connection'); |
bdebd63dbab3
Tests: keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1665
diff
changeset
|
131 |
1668
0c1bd4c23c95
Tests: $connection_requests and $connection_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1667
diff
changeset
|
132 like($r, qr/X-Conn: 1:0.*X-Conn: 2:[^0]/s, 'keepalive time limit variables'); |
0c1bd4c23c95
Tests: $connection_requests and $connection_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1667
diff
changeset
|
133 |
1665
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
134 # cancel keepalive on EOF while discarding body |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
135 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
136 my $s = http(<<EOF, start => 1); |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
137 POST /r HTTP/1.1 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
138 Host: localhost |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
139 Content-Length: 10 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
140 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
141 EOF |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
142 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
143 read_keepalive($s); |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
144 shutdown($s, 1); |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
145 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
146 TODO: { |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
147 local $TODO = 'not yet' unless ($^O eq 'MSWin32' or $^O eq 'solaris') |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
148 or $t->has_version('1.19.9'); |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
149 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
150 ok(IO::Select->new($s)->can_read(3), 'EOF in discard body'); |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
151 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
152 } |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
153 |
1509
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
154 $t->stop(); |
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
155 |
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
156 TODO: { |
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
157 local $TODO = 'not yet'; |
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
158 |
1663
bf69dcabb856
Tests: $sent_http_keep_alive tests (ticket #1850).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1509
diff
changeset
|
159 is($t->read_file('test1.log'), "keep-alive\nclose\n", 'sent_http_connection'); |
bf69dcabb856
Tests: $sent_http_keep_alive tests (ticket #1850).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1509
diff
changeset
|
160 is($t->read_file('test2.log'), "timeout=9\n-\n", 'sent_http_keep_alive'); |
1509
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
161 |
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
162 } |
1603f2bad385
Tests: $sent_http_connection tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1508
diff
changeset
|
163 |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
164 ############################################################################### |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
165 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
166 sub http_keepalive { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
167 my ($url, %opts) = @_; |
1508
1a409a166420
Tests: fixed http_keepalive.t with short reads and double logging.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1361
diff
changeset
|
168 my $total = ''; |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
169 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
170 $opts{ua} = $opts{ua} || ''; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
171 $opts{req} = $opts{req} || 1; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
172 $opts{sleep} = $opts{sleep} || 0; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
173 $opts{method} = $opts{method} || 'GET'; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
174 |
1166
2b8523bd4988
Tests: handled broken connections in http_keepalive.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1023
diff
changeset
|
175 local $SIG{PIPE} = 'IGNORE'; |
2b8523bd4988
Tests: handled broken connections in http_keepalive.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1023
diff
changeset
|
176 |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
177 my $s = http('', start => 1); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
178 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
179 for my $i (1 .. $opts{req}) { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
180 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
181 my $sleep = ($i == 1 ? $opts{sleep} : 0); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
182 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
183 http(<<EOF, socket => $s, start => 1, sleep => $sleep); |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
184 $opts{method} $url HTTP/1.1 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
185 Host: localhost |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
186 User-Agent: $opts{ua} |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
187 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
188 EOF |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
189 |
1665
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
190 $total .= read_keepalive($s); |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
191 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
192 |
1508
1a409a166420
Tests: fixed http_keepalive.t with short reads and double logging.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1361
diff
changeset
|
193 return $total; |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
194 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
195 |
1665
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
196 sub read_keepalive { |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
197 my ($s) = @_; |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
198 my $data = ''; |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
199 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
200 while (IO::Select->new($s)->can_read(3)) { |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
201 sysread($s, my $buffer, 4096) or last; |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
202 $data .= $buffer; |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
203 last if $data =~ /^\x0d\x0a/ms; |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
204 } |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
205 |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
206 log_in($data); |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
207 return $data; |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
208 } |
a40f94bc92d4
Tests: keepalive test with EOF in discard body (ticket #2145).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1663
diff
changeset
|
209 |
1023
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
210 sub count_keepalive { |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
211 my ($str) = @_; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
212 return $str =~ s/Connection: keep-alive//g; |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
213 } |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
214 |
8533222fcfc1
Tests: http keepalive tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
215 ############################################################################### |