comparison http_resolver.t @ 436:4984dac109db

Tests: added test for resolver resend.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 16 Jul 2014 13:08:33 +0400
parents 847ea345becb
children 60888e2c3f5a
comparison
equal deleted inserted replaced
435:a7d04159e52b 436:4984dac109db
63 proxy_pass http://$http_x_name:8080/backend; 63 proxy_pass http://$http_x_name:8080/backend;
64 } 64 }
65 location /invalid { 65 location /invalid {
66 proxy_pass http://$host:8080/backend; 66 proxy_pass http://$host:8080/backend;
67 } 67 }
68 location /resend {
69 resolver 127.0.0.1:8081;
70 resolver_timeout 6s;
71 proxy_pass http://$host:8080/backend;
72 }
68 73
69 location /backend { 74 location /backend {
70 return 200; 75 return 200;
71 } 76 }
72 location /50x { 77 location /50x {
78 EOF 83 EOF
79 84
80 $t->run_daemon(\&dns_daemon, 8081, $t); 85 $t->run_daemon(\&dns_daemon, 8081, $t);
81 $t->run_daemon(\&dns_daemon, 8082, $t); 86 $t->run_daemon(\&dns_daemon, 8082, $t);
82 87
83 $t->run()->plan(30); 88 $t->run()->plan(31);
84 89
85 $t->waitforfile($t->testdir . '/8081'); 90 $t->waitforfile($t->testdir . '/8081');
86 $t->waitforfile($t->testdir . '/8082'); 91 $t->waitforfile($t->testdir . '/8082');
87 92
88 ############################################################################### 93 ###############################################################################
94
95 # schedule resend test, which takes abound 5 seconds to complete
96
97 my $s = http_start('id.example.net', '/resend');
89 98
90 like(http_host_header('a.example.net', '/'), qr/200 OK/, 'A'); 99 like(http_host_header('a.example.net', '/'), qr/200 OK/, 'A');
91 100
92 # ensure that resolver serves queries from cache in a case-insensitive manner 101 # ensure that resolver serves queries from cache in a case-insensitive manner
93 # we check this by marking 2nd and subsequent queries on backend with SERVFAIL 102 # we check this by marking 2nd and subsequent queries on backend with SERVFAIL
209 218
210 like(http_host_header('cname_a_ttl2.example.net', '/'), qr/502 Bad/, 219 like(http_host_header('cname_a_ttl2.example.net', '/'), qr/502 Bad/,
211 'CNAME + A with expired CNAME ttl'); 220 'CNAME + A with expired CNAME ttl');
212 221
213 like(http_host_header('example.net', '/invalid'), qr/502 Bad/, 'no resolver'); 222 like(http_host_header('example.net', '/invalid'), qr/502 Bad/, 'no resolver');
223
224 TODO: {
225 local $TODO = 'not yet' unless $t->has_version('1.7.4');
226
227 like(http_end($s), qr/200 OK/, 'resend after malformed response');
228
229 }
214 230
215 ############################################################################### 231 ###############################################################################
216 232
217 sub http_host_header { 233 sub http_host_header {
218 my ($host, $uri) = @_; 234 my ($host, $uri) = @_;
228 return http(<<EOF); 244 return http(<<EOF);
229 GET $uri HTTP/1.0 245 GET $uri HTTP/1.0
230 X-Name: $host 246 X-Name: $host
231 247
232 EOF 248 EOF
249 }
250
251 sub http_start {
252 my ($host, $uri) = @_;
253
254 my $s;
255 my $request = <<EOF;
256 GET $uri HTTP/1.0
257 Host: $host
258
259 EOF
260
261 eval {
262 local $SIG{ALRM} = sub { die "timeout\n" };
263 local $SIG{PIPE} = sub { die "sigpipe\n" };
264 alarm(5);
265 $s = IO::Socket::INET->new(
266 Proto => 'tcp',
267 PeerAddr => '127.0.0.1:8080'
268 );
269 log_out($request);
270 $s->print($request);
271 alarm(0);
272 };
273 alarm(0);
274 if ($@) {
275 log_in("died: $@");
276 return undef;
277 }
278 return $s;
279 }
280
281 sub http_end {
282 my ($s) = @_;
283 my $reply;
284
285 eval {
286 local $SIG{ALRM} = sub { die "timeout\n" };
287 local $SIG{PIPE} = sub { die "sigpipe\n" };
288 alarm(3);
289 local $/;
290 $reply = $s->getline();
291 log_in($reply);
292 alarm(0);
293 };
294 alarm(0);
295 if ($@) {
296 log_in("died: $@");
297 return undef;
298 }
299 return $reply;
233 } 300 }
234 301
235 ############################################################################### 302 ###############################################################################
236 303
237 sub reply_handler { 304 sub reply_handler {
274 } 341 }
275 342
276 } elsif ($name eq 'case.example.net' && $type == A) { 343 } elsif ($name eq 'case.example.net' && $type == A) {
277 if (++$state->{casecnt} > 1) { 344 if (++$state->{casecnt} > 1) {
278 $rcode = SERVFAIL; 345 $rcode = SERVFAIL;
346 }
347
348 push @rdata, rd_addr($ttl, '127.0.0.1');
349
350 } elsif ($name eq 'id.example.net' && $type == A) {
351 if (++$state->{idcnt} == 1) {
352 $id++;
279 } 353 }
280 354
281 push @rdata, rd_addr($ttl, '127.0.0.1'); 355 push @rdata, rd_addr($ttl, '127.0.0.1');
282 356
283 } elsif ($name eq 'awide.example.net' && $type == A) { 357 } elsif ($name eq 'awide.example.net' && $type == A) {
432 ttl0cnt => 0, 506 ttl0cnt => 0,
433 cttlcnt => 0, 507 cttlcnt => 0,
434 cttl2cnt => 0, 508 cttl2cnt => 0,
435 manycnt => 0, 509 manycnt => 0,
436 casecnt => 0, 510 casecnt => 0,
511 idcnt => 0,
437 ); 512 );
438 513
439 # signal we are ready 514 # signal we are ready
440 515
441 open my $fh, '>', $t->testdir() . '/' . $port; 516 open my $fh, '>', $t->testdir() . '/' . $port;