Mercurial > hg > nginx-tests
comparison proxy_variables.t @ 1403:3783b937a1dc
Tests: added upstream response time tests with client close.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 21 Nov 2018 15:38:50 +0300 |
parents | db77d757ded4 |
children | a1a3164faec8 |
comparison
equal
deleted
inserted
replaced
1402:db77d757ded4 | 1403:3783b937a1dc |
---|---|
20 ############################################################################### | 20 ############################################################################### |
21 | 21 |
22 select STDERR; $| = 1; | 22 select STDERR; $| = 1; |
23 select STDOUT; $| = 1; | 23 select STDOUT; $| = 1; |
24 | 24 |
25 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(19) | 25 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(22) |
26 ->write_file_expand('nginx.conf', <<'EOF'); | 26 ->write_file_expand('nginx.conf', <<'EOF'); |
27 | 27 |
28 %%TEST_GLOBALS%% | 28 %%TEST_GLOBALS%% |
29 | 29 |
30 daemon off; | 30 daemon off; |
82 | 82 |
83 ############################################################################### | 83 ############################################################################### |
84 | 84 |
85 my $re = qr/(\d\.\d{3})/; | 85 my $re = qr/(\d\.\d{3})/; |
86 my $p0 = port(8080); | 86 my $p0 = port(8080); |
87 my ($ct, $ht, $rt, $ct2, $ht2, $rt2); | 87 my ($ct, $ht, $rt, $ct2, $ht2, $rt2, $ct3, $ht3, $rt3); |
88 | 88 |
89 like(http_get('/vars'), qr/X-Proxy-Host:\s127\.0\.0\.1:$p0/, 'proxy_host'); | 89 like(http_get('/vars'), qr/X-Proxy-Host:\s127\.0\.0\.1:$p0/, 'proxy_host'); |
90 like(http_get('/vars'), qr/X-Proxy-Port:\s$p0/, 'proxy_port'); | 90 like(http_get('/vars'), qr/X-Proxy-Port:\s$p0/, 'proxy_port'); |
91 like(http_xff('/vars', '192.0.2.1'), qr/X-Proxy-Forwarded:.*192\.0\.2\.1/, | 91 like(http_xff('/vars', '192.0.2.1'), qr/X-Proxy-Forwarded:.*192\.0\.2\.1/, |
92 'proxy_add_x_forwarded_for'); | 92 'proxy_add_x_forwarded_for'); |
97 | 97 |
98 ($ct, $ht) = get('/body'); | 98 ($ct, $ht) = get('/body'); |
99 cmp_ok($ct, '<', 1, 'connect time - slow response body'); | 99 cmp_ok($ct, '<', 1, 'connect time - slow response body'); |
100 cmp_ok($ht, '<', 1, 'header time - slow response body'); | 100 cmp_ok($ht, '<', 1, 'header time - slow response body'); |
101 | 101 |
102 my $s = http_get('/header_close', start => 1); | |
103 select undef, undef, undef, 0.4; | |
104 close ($s); | |
105 | |
102 # expect no header time in 1st (bad) upstream, no (yet) response time in 2nd | 106 # expect no header time in 1st (bad) upstream, no (yet) response time in 2nd |
103 | 107 |
104 $re = qr/(\d\.\d{3}|-)/; | 108 $re = qr/(\d\.\d{3}|-)/; |
105 ($ct, $ct2, $ht, $ht2, $rt, $rt2) = get('/pnu', many => 1); | 109 ($ct, $ct2, $ht, $ht2, $rt, $rt2) = get('/pnu', many => 1); |
106 cmp_ok($ct, '<', 1, 'connect time - next'); | 110 cmp_ok($ct, '<', 1, 'connect time - next'); |
123 | 127 |
124 } | 128 } |
125 | 129 |
126 $t->stop(); | 130 $t->stop(); |
127 | 131 |
128 $re = qr/(\d\.\d{3})/; | 132 ($ct, $ht, $rt, $ct2, $ht2, $rt2, $ct3, $ht3, $rt3) |
129 ($ct, $ht, $rt, $ct2, $ht2, $rt2) | 133 = $t->read_file('time.log') =~ /^$re:$re:$re\n$re:$re:$re\n$re:$re:$re$/; |
130 = $t->read_file('time.log') =~ /^$re:$re:$re\n$re:$re:$re$/; | |
131 | 134 |
132 cmp_ok($ct, '<', 1, 'connect time log - slow response header'); | 135 cmp_ok($ct, '<', 1, 'connect time log - slow response header'); |
133 cmp_ok($ct2, '<', 1, 'connect time log - slow response body'); | 136 cmp_ok($ct2, '<', 1, 'connect time log - slow response body'); |
134 | 137 |
138 TODO: { | |
139 local $TODO = 'not yet' unless $t->has_version('1.15.7'); | |
140 | |
141 cmp_ok($ct3, '<', 1, 'connect time log - client close'); | |
142 | |
143 } | |
144 | |
135 cmp_ok($ht, '>=', 1, 'header time log - slow response header'); | 145 cmp_ok($ht, '>=', 1, 'header time log - slow response header'); |
136 cmp_ok($ht2, '<', 1, 'header time log - slow response body'); | 146 cmp_ok($ht2, '<', 1, 'header time log - slow response body'); |
147 is($ht3, '-', 'header time log - client close'); | |
137 | 148 |
138 cmp_ok($rt, '>=', 1, 'response time log - slow response header'); | 149 cmp_ok($rt, '>=', 1, 'response time log - slow response header'); |
139 cmp_ok($rt2, '>=', 1, 'response time log - slow response body'); | 150 cmp_ok($rt2, '>=', 1, 'response time log - slow response body'); |
151 | |
152 TODO: { | |
153 local $TODO = 'not yet' unless $t->has_version('1.15.7'); | |
154 | |
155 cmp_ok($rt3, '>', $ct3, 'response time log - client close'); | |
156 | |
157 } | |
140 | 158 |
141 ############################################################################### | 159 ############################################################################### |
142 | 160 |
143 sub get { | 161 sub get { |
144 my ($uri, %extra) = @_; | 162 my ($uri, %extra) = @_; |