Mercurial > hg > nginx-tests
annotate proxy.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 144c6ce732e4 |
children |
rev | line source |
---|---|
42 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for http proxy module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
121
8ac1faaddd2c
Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents:
107
diff
changeset
|
12 use Test::More; |
42 | 13 |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1461
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(28); |
42 | 25 |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
83
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
83
diff
changeset
|
29 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
30 daemon off; |
42 | 31 |
32 events { | |
33 } | |
34 | |
35 http { | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
83
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
42 | 37 |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
38 log_format time '$upstream_connect_time:$upstream_header_time:' |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
39 '$upstream_response_time'; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
40 |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
41 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 server 127.0.0.1:8081; |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
43 } |
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
44 |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
45 upstream u2 { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
46 server 127.0.0.1:8081; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
47 server 127.0.0.1:8081; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
48 } |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
49 |
42 | 50 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 listen 127.0.0.1:8080; |
42 | 52 server_name localhost; |
731
cf9183219c59
Tests: removed debugging leftover.
Sergey Kandaurov <pluknet@nginx.com>
parents:
717
diff
changeset
|
53 |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
54 add_header X-Connect $upstream_connect_time; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
55 add_header X-Header $upstream_header_time; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
56 add_header X-Response $upstream_response_time; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
57 |
42 | 58 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 proxy_pass http://127.0.0.1:8081; |
1461
7959e58429d0
Tests: adjusted proxy.t proxy_read_timeout for slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1460
diff
changeset
|
60 proxy_read_timeout 2s; |
795
122cd3a82367
Tests: fixed 'proxy connect timeout' test timeouts on slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
732
diff
changeset
|
61 proxy_connect_timeout 2s; |
42 | 62 } |
434 | 63 |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
64 location /var { |
434 | 65 proxy_pass http://$arg_b; |
1461
7959e58429d0
Tests: adjusted proxy.t proxy_read_timeout for slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1460
diff
changeset
|
66 proxy_read_timeout 2s; |
1006
e4d5e7afb6e0
Tests: speed up proxy.t on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
67 proxy_connect_timeout 2s; |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
68 } |
1079
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
69 |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
70 location /timeout { |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
71 proxy_pass http://127.0.0.1:8081; |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
72 proxy_connect_timeout 2s; |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
73 } |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
74 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
75 location /time/ { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
76 proxy_pass http://127.0.0.1:8081/; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
77 access_log %%TESTDIR%%/time.log time; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
78 } |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
79 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
80 location /pnu { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
81 proxy_pass http://u2/bad; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
82 } |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
83 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
84 location /vars { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
85 proxy_pass http://127.0.0.1:8080/stub; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
86 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
87 add_header X-Proxy-Host $proxy_host; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
88 add_header X-Proxy-Port $proxy_port; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
89 add_header X-Proxy-Forwarded $proxy_add_x_forwarded_for; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
90 } |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
91 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
92 location /stub { } |
42 | 93 } |
94 } | |
95 | |
96 EOF | |
97 | |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
98 $t->write_file('stub', ''); |
42 | 99 $t->run_daemon(\&http_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
100 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
42 | 101 |
102 ############################################################################### | |
103 | |
104 like(http_get('/'), qr/SEE-THIS/, 'proxy request'); | |
105 like(http_get('/multi'), qr/AND-THIS/, 'proxy request with multiple packets'); | |
106 | |
107 unlike(http_head('/'), qr/SEE-THIS/, 'proxy head request'); | |
108 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
109 like(http_get('/var?b=127.0.0.1:' . port(8081) . '/'), qr/SEE-THIS/, |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
924
diff
changeset
|
110 'proxy with variables'); |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
111 like(http_get('/var?b=u/'), qr/SEE-THIS/, 'proxy with variables to upstream'); |
922
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
112 |
1079
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
113 like(http_get('/timeout'), qr/200 OK/, 'proxy connect timeout'); |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
114 |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
115 my $re = qr/(\d\.\d{3})/; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
116 my $p0 = port(8080); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
117 my ($ct, $ht, $rt, $ct2, $ht2, $rt2, $ct3, $ht3, $rt3); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
118 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
119 like(http_get('/vars'), qr/X-Proxy-Host:\s127\.0\.0\.1:$p0/, 'proxy_host'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
120 like(http_get('/vars'), qr/X-Proxy-Port:\s$p0/, 'proxy_port'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
121 like(http_xff('/vars', '192.0.2.1'), qr/X-Proxy-Forwarded:.*192\.0\.2\.1/, |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
122 'proxy_add_x_forwarded_for'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
123 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
124 ($ct, $ht) = get('/time/header'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
125 cmp_ok($ct, '<', 1, 'connect time - slow response header'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
126 cmp_ok($ht, '>=', 1, 'header time - slow response header'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
127 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
128 ($ct, $ht) = get('/time/body'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
129 cmp_ok($ct, '<', 1, 'connect time - slow response body'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
130 cmp_ok($ht, '<', 1, 'header time - slow response body'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
131 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
132 my $s = http_get('/time/header', start => 1); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
133 select undef, undef, undef, 0.4; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
134 close ($s); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
135 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
136 # expect no header time in 1st (bad) upstream, no (yet) response time in 2nd |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
137 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
138 $re = qr/(\d\.\d{3}|-)/; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
139 ($ct, $ct2, $ht, $ht2, $rt, $rt2) = get('/pnu', many => 1); |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1461
diff
changeset
|
140 |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
141 cmp_ok($ct, '<', 1, 'connect time - next'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
142 cmp_ok($ct2, '<', 1, 'connect time - next 2'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
143 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
144 is($ht, '-', 'header time - next'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
145 cmp_ok($ht2, '<', 1, 'header time - next 2'); |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1461
diff
changeset
|
146 |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
147 cmp_ok($rt, '>=', 1, 'response time - next'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
148 is($rt2, '-', 'response time - next 2'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
149 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
150 $t->stop(); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
151 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
152 ($ct, $ht, $rt, $ct2, $ht2, $rt2, $ct3, $ht3, $rt3) |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
153 = $t->read_file('time.log') =~ /^$re:$re:$re\n$re:$re:$re\n$re:$re:$re$/; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
154 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
155 cmp_ok($ct, '<', 1, 'connect time log - slow response header'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
156 cmp_ok($ct2, '<', 1, 'connect time log - slow response body'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
157 cmp_ok($ct3, '<', 1, 'connect time log - client close'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
158 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
159 cmp_ok($ht, '>=', 1, 'header time log - slow response header'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
160 cmp_ok($ht2, '<', 1, 'header time log - slow response body'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
161 is($ht3, '-', 'header time log - client close'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
162 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
163 cmp_ok($rt, '>=', 1, 'response time log - slow response header'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
164 cmp_ok($rt2, '>=', 1, 'response time log - slow response body'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
165 cmp_ok($rt3, '>', $ct3, 'response time log - client close'); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
166 |
42 | 167 ############################################################################### |
168 | |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
169 sub get { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
170 my ($uri, %extra) = @_; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
171 my $re = $extra{many} ? qr/$re, $re?/ : $re; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
172 my $r = http_get($uri); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
173 $r =~ /X-Connect: $re/, $r =~ /X-Header: $re/, $r =~ /X-Response: $re/; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
174 } |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
175 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
176 sub http_xff { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
177 my ($uri, $xff) = @_; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
178 return http(<<EOF); |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
179 GET $uri HTTP/1.0 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
180 Host: localhost |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
181 X-Forwarded-For: $xff |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
182 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
183 EOF |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
184 } |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
185 |
42 | 186 sub http_daemon { |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
187 my $once = 1; |
42 | 188 my $server = IO::Socket::INET->new( |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
189 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
190 LocalHost => '127.0.0.1:' . port(8081), |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
191 Listen => 5, |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
192 Reuse => 1 |
42 | 193 ) |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
194 or die "Can't create listening socket: $!\n"; |
42 | 195 |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
196 local $SIG{PIPE} = 'IGNORE'; |
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
197 |
42 | 198 while (my $client = $server->accept()) { |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
199 $client->autoflush(1); |
42 | 200 |
201 my $headers = ''; | |
202 my $uri = ''; | |
203 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
204 while (<$client>) { |
42 | 205 $headers .= $_; |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
206 last if (/^\x0d?\x0a?$/); |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
207 } |
42 | 208 |
209 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
210 | |
211 if ($uri eq '/') { | |
212 print $client <<'EOF'; | |
213 HTTP/1.1 200 OK | |
214 Connection: close | |
215 | |
216 EOF | |
217 print $client "TEST-OK-IF-YOU-SEE-THIS" | |
218 unless $headers =~ /^HEAD/i; | |
219 | |
220 } elsif ($uri eq '/multi') { | |
221 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
222 print $client <<"EOF"; |
42 | 223 HTTP/1.1 200 OK |
224 Connection: close | |
225 | |
226 TEST-OK-IF-YOU-SEE-THIS | |
227 EOF | |
228 | |
229 select undef, undef, undef, 0.1; | |
230 print $client 'AND-THIS'; | |
231 | |
1079
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
232 } elsif ($uri eq '/timeout') { |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
233 sleep 3; |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
234 |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
235 print $client <<"EOF"; |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
236 HTTP/1.1 200 OK |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
237 Connection: close |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
238 |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
239 EOF |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
240 |
1419
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
241 } elsif ($uri eq '/bad') { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
242 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
243 if ($once) { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
244 $once = 0; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
245 select undef, undef, undef, 1.1; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
246 next; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
247 } |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
248 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
249 print $client <<EOF; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
250 HTTP/1.1 200 OK |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
251 Connection: close |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
252 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
253 SEE-THIS-AND-THIS |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
254 EOF |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
255 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
256 } elsif ($uri eq '/header') { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
257 select undef, undef, undef, 1.1; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
258 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
259 print $client <<EOF; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
260 HTTP/1.1 200 OK |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
261 Connection: close |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
262 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
263 SEE-THIS-AND-THIS; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
264 EOF |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
265 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
266 } elsif ($uri eq '/body') { |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
267 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
268 print $client <<EOF; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
269 HTTP/1.1 200 OK |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
270 Connection: close |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
271 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
272 SEE-THIS- |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
273 EOF |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
274 |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
275 select undef, undef, undef, 1.1; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
276 print $client 'AND-THIS'; |
16a8962ff246
Tests: upstream_response_length_variable tests, proxy.t merged.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
277 |
42 | 278 } else { |
279 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
280 print $client <<"EOF"; |
42 | 281 HTTP/1.1 404 Not Found |
282 Connection: close | |
283 | |
284 Oops, '$uri' not found | |
285 EOF | |
286 } | |
287 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
288 close $client; |
42 | 289 } |
290 } | |
291 | |
292 ############################################################################### |