Mercurial > hg > nginx-tests
comparison proxy_next_upstream_tries.t @ 479:b8f10ffa02cd
Tests: proxy_next_upstream_tries tests with resolved upstream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 27 Oct 2014 16:48:49 +0300 |
parents | cb0662e12d6e |
children | cebd7b8ca5b8 |
comparison
equal
deleted
inserted
replaced
478:fec6dc7e0fc3 | 479:b8f10ffa02cd |
---|---|
77 location /tries/backup { | 77 location /tries/backup { |
78 proxy_pass http://u2; | 78 proxy_pass http://u2; |
79 proxy_next_upstream_tries 2; | 79 proxy_next_upstream_tries 2; |
80 } | 80 } |
81 | 81 |
82 location /tries/resolver { | |
83 resolver 127.0.0.1:8083; | |
84 resolver_timeout 1s; | |
85 | |
86 proxy_pass http://$host:8081/backend; | |
87 proxy_next_upstream_tries 2; | |
88 } | |
89 | |
82 location /timeout { | 90 location /timeout { |
83 proxy_pass http://u3; | 91 proxy_pass http://u3; |
84 proxy_next_upstream_timeout 1500ms; | 92 proxy_next_upstream_timeout 1500ms; |
85 } | 93 } |
86 | 94 |
87 location /timeout/backup { | 95 location /timeout/backup { |
88 proxy_pass http://u4; | 96 proxy_pass http://u4; |
89 proxy_next_upstream_timeout 1500ms; | 97 proxy_next_upstream_timeout 1500ms; |
90 } | 98 } |
91 | 99 |
100 location /timeout/resolver { | |
101 resolver 127.0.0.1:8083; | |
102 resolver_timeout 1s; | |
103 | |
104 proxy_pass http://$host:8082/backend; | |
105 proxy_next_upstream_timeout 1500ms; | |
106 } | |
107 | |
92 location /404 { | 108 location /404 { |
93 return 200 x${upstream_status}x; | 109 return 200 x${upstream_status}x; |
94 } | 110 } |
95 } | 111 } |
96 } | 112 } |
97 | 113 |
98 EOF | 114 EOF |
99 | 115 |
100 $t->run_daemon(\&http_daemon, 8081); | 116 $t->run_daemon(\&http_daemon, 8081); |
101 $t->run_daemon(\&http_daemon, 8082); | 117 $t->run_daemon(\&http_daemon, 8082); |
102 $t->try_run('no proxy_next_upstream_tries')->plan(4); | 118 $t->run_daemon(\&dns_daemon, 8083, $t); |
119 $t->try_run('no proxy_next_upstream_tries')->plan(6); | |
103 | 120 |
104 $t->waitforsocket('127.0.0.1:8081'); | 121 $t->waitforsocket('127.0.0.1:8081'); |
105 $t->waitforsocket('127.0.0.1:8082'); | 122 $t->waitforsocket('127.0.0.1:8082'); |
123 $t->waitforfile($t->testdir . '/8083'); | |
106 | 124 |
107 ############################################################################### | 125 ############################################################################### |
108 | 126 |
109 like(http_get('/tries'), qr/x404, 404x/, 'tries'); | 127 like(http_get('/tries'), qr/x404, 404x/, 'tries'); |
110 like(http_get('/tries/backup'), qr/x404, 404x/, 'tries backup'); | 128 like(http_get('/tries/backup'), qr/x404, 404x/, 'tries backup'); |
111 | 129 |
130 TODO: { | |
131 local $TODO = 'not yet'; | |
132 | |
133 like(http_get('/tries/resolver'), qr/x404, 404x/, 'tries resolved'); | |
134 | |
135 } | |
136 | |
112 # two tries fit into 1.5s | 137 # two tries fit into 1.5s |
113 | 138 |
114 like(http_get('/timeout'), qr/x404, 404x/, 'timeout'); | 139 like(http_get('/timeout'), qr/x404, 404x/, 'timeout'); |
115 like(http_get('/timeout/backup'), qr/x404, 404x/, 'timeout backup'); | 140 like(http_get('/timeout/backup'), qr/x404, 404x/, 'timeout backup'); |
141 | |
142 TODO: { | |
143 local $TODO = 'not yet'; | |
144 | |
145 like(http_get('/timeout/resolver'), qr/x404, 404x/, 'timeout resolved'); | |
146 | |
147 } | |
116 | 148 |
117 ############################################################################### | 149 ############################################################################### |
118 | 150 |
119 sub http_daemon { | 151 sub http_daemon { |
120 my ($port) = @_; | 152 my ($port) = @_; |
157 } continue { | 189 } continue { |
158 close $client; | 190 close $client; |
159 } | 191 } |
160 } | 192 } |
161 | 193 |
162 ############################################################################### | 194 sub reply_handler { |
195 my ($recv_data) = @_; | |
196 | |
197 my (@name, @rdata); | |
198 | |
199 use constant NOERROR => 0; | |
200 use constant A => 1; | |
201 use constant IN => 1; | |
202 | |
203 # default values | |
204 | |
205 my ($hdr, $rcode, $ttl) = (0x8180, NOERROR, 3600); | |
206 | |
207 # decode name | |
208 | |
209 my ($len, $offset) = (undef, 12); | |
210 while (1) { | |
211 $len = unpack("\@$offset C", $recv_data); | |
212 last if $len == 0; | |
213 $offset++; | |
214 push @name, unpack("\@$offset A$len", $recv_data); | |
215 $offset += $len; | |
216 } | |
217 | |
218 $offset -= 1; | |
219 my ($id, $type, $class) = unpack("n x$offset n2", $recv_data); | |
220 | |
221 @rdata = map { rd_addr($ttl, '127.0.0.1') } (1 .. 3); | |
222 | |
223 $len = @name; | |
224 pack("n6 (w/a*)$len x n2", $id, $hdr | $rcode, 1, scalar @rdata, | |
225 0, 0, @name, $type, $class) . join('', @rdata); | |
226 } | |
227 | |
228 sub rd_addr { | |
229 my ($ttl, $addr) = @_; | |
230 | |
231 my $code = 'split(/\./, $addr)'; | |
232 | |
233 return pack 'n3N', 0xc00c, A, IN, $ttl if $addr eq ''; | |
234 | |
235 pack 'n3N nC4', 0xc00c, A, IN, $ttl, eval "scalar $code", eval($code); | |
236 } | |
237 | |
238 sub dns_daemon { | |
239 my ($port, $t) = @_; | |
240 | |
241 my ($data, $recv_data); | |
242 my $socket = IO::Socket::INET->new( | |
243 LocalAddr => '127.0.0.1', | |
244 LocalPort => $port, | |
245 Proto => 'udp', | |
246 ) | |
247 or die "Can't create listening socket: $!\n"; | |
248 | |
249 # signal we are ready | |
250 | |
251 open my $fh, '>', $t->testdir() . '/' . $port; | |
252 close $fh; | |
253 | |
254 while (1) { | |
255 $socket->recv($recv_data, 65536); | |
256 $data = reply_handler($recv_data); | |
257 $socket->send($data); | |
258 } | |
259 } | |
260 | |
261 ############################################################################### |