Mercurial > hg > nginx-tests
comparison http_resolver.t @ 952:e9064d691790
Tests: converted tests to run in parallel.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Tue, 21 Jun 2016 16:39:13 +0300 |
parents | b1fa8e0cc27b |
children | 3bc5b72e4377 |
comparison
equal
deleted
inserted
replaced
951:9361c7eddfc1 | 952:e9064d691790 |
---|---|
37 | 37 |
38 http { | 38 http { |
39 %%TEST_GLOBALS_HTTP%% | 39 %%TEST_GLOBALS_HTTP%% |
40 | 40 |
41 server { | 41 server { |
42 listen 127.0.0.1:8080; | 42 listen 127.0.0.1:%%PORT_0%%; |
43 server_name localhost; | 43 server_name localhost; |
44 | 44 |
45 location / { | 45 location / { |
46 resolver 127.0.0.1:8081; | 46 resolver 127.0.0.1:%%PORT_1_UDP%%; |
47 resolver_timeout 1s; | 47 resolver_timeout 1s; |
48 proxy_pass http://$host:8080/backend; | 48 proxy_pass http://$host:%%PORT_0%%/backend; |
49 | 49 |
50 proxy_next_upstream http_504 timeout error; | 50 proxy_next_upstream http_504 timeout error; |
51 proxy_intercept_errors on; | 51 proxy_intercept_errors on; |
52 proxy_connect_timeout 1s; | 52 proxy_connect_timeout 1s; |
53 error_page 504 502 /50x; | 53 error_page 504 502 /50x; |
54 } | 54 } |
55 location /two { | 55 location /two { |
56 resolver 127.0.0.1:8081 127.0.0.1:8082; | 56 resolver 127.0.0.1:%%PORT_1_UDP%% 127.0.0.1:%%PORT_2_UDP%%; |
57 proxy_pass http://$host:8080/backend; | 57 proxy_pass http://$host:%%PORT_0%%/backend; |
58 } | 58 } |
59 location /valid { | 59 location /valid { |
60 resolver 127.0.0.1:8081 valid=5s; | 60 resolver 127.0.0.1:%%PORT_1_UDP%% valid=5s; |
61 proxy_pass http://$host:8080/backend; | 61 proxy_pass http://$host:%%PORT_0%%/backend; |
62 } | 62 } |
63 location /case { | 63 location /case { |
64 resolver 127.0.0.1:8081; | 64 resolver 127.0.0.1:%%PORT_1_UDP%%; |
65 proxy_pass http://$http_x_name:8080/backend; | 65 proxy_pass http://$http_x_name:%%PORT_0%%/backend; |
66 } | 66 } |
67 location /invalid { | 67 location /invalid { |
68 proxy_pass http://$host:8080/backend; | 68 proxy_pass http://$host:%%PORT_0%%/backend; |
69 } | 69 } |
70 location /long { | 70 location /long { |
71 resolver 127.0.0.1:8081; | 71 resolver 127.0.0.1:%%PORT_1_UDP%%; |
72 resolver_timeout 4s; | 72 resolver_timeout 4s; |
73 proxy_pass http://$host:8080/backend; | 73 proxy_pass http://$host:%%PORT_0%%/backend; |
74 } | 74 } |
75 location /resend { | 75 location /resend { |
76 resolver 127.0.0.1:8081; | 76 resolver 127.0.0.1:%%PORT_1_UDP%%; |
77 resolver_timeout 8s; | 77 resolver_timeout 8s; |
78 proxy_pass http://$host:8080/backend; | 78 proxy_pass http://$host:%%PORT_0%%/backend; |
79 } | 79 } |
80 location /bad { | 80 location /bad { |
81 resolver 127.0.0.1:8089; | 81 resolver 127.0.0.1:%%PORT_4_UDP%%; |
82 resolver_timeout 1s; | 82 resolver_timeout 1s; |
83 proxy_pass http://$host:8080/backend; | 83 proxy_pass http://$host:%%PORT_0%%/backend; |
84 } | 84 } |
85 location /tcp { | 85 location /tcp { |
86 resolver 127.0.0.1:8083 127.0.0.1:8082; | 86 resolver 127.0.0.1:%%PORT_3_UDP%% 127.0.0.1:%%PORT_2_UDP%%; |
87 resolver_timeout 1s; | 87 resolver_timeout 1s; |
88 proxy_pass http://$host:8080/backend; | 88 proxy_pass http://$host:%%PORT_0%%/backend; |
89 proxy_connect_timeout 1s; | 89 proxy_connect_timeout 1s; |
90 add_header X-IP $upstream_addr; | 90 add_header X-IP $upstream_addr; |
91 error_page 504 502 /50x; | 91 error_page 504 502 /50x; |
92 | 92 |
93 location /tcp2 { | 93 location /tcp2 { |
94 resolver_timeout 8s; | 94 resolver_timeout 8s; |
95 proxy_pass http://$host:8080/backend; | 95 proxy_pass http://$host:%%PORT_0%%/backend; |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 location /backend { | 99 location /backend { |
100 return 200; | 100 return 200; |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 EOF | 108 EOF |
109 | 109 |
110 $t->run_daemon(\&dns_daemon, 8081, $t); | 110 $t->run_daemon(\&dns_daemon, port(1), $t); |
111 $t->run_daemon(\&dns_daemon, 8082, $t); | 111 $t->run_daemon(\&dns_daemon, port(2), $t); |
112 $t->run_daemon(\&dns_daemon, 8083, $t, tcp => 1); | 112 $t->run_daemon(\&dns_daemon, port(3), $t, tcp => 1); |
113 $t->run_daemon(\&dns_daemon, 8089, $t); | 113 $t->run_daemon(\&dns_daemon, port(4), $t); |
114 | 114 |
115 $t->run()->plan(38); | 115 $t->run()->plan(38); |
116 | 116 |
117 $t->waitforfile($t->testdir . '/8081'); | 117 $t->waitforfile($t->testdir . '/' . port(1)); |
118 $t->waitforfile($t->testdir . '/8082'); | 118 $t->waitforfile($t->testdir . '/' . port(2)); |
119 $t->waitforfile($t->testdir . '/8083'); | 119 $t->waitforfile($t->testdir . '/' . port(3)); |
120 $t->waitforfile($t->testdir . '/8089'); | 120 $t->waitforfile($t->testdir . '/' . port(4)); |
121 | 121 |
122 ############################################################################### | 122 ############################################################################### |
123 | |
124 my $p0 = port(0); | |
123 | 125 |
124 # schedule resend test, which takes about 5 seconds to complete | 126 # schedule resend test, which takes about 5 seconds to complete |
125 | 127 |
126 my $s = http_host_header('id.example.net', '/resend', start => 1); | 128 my $s = http_host_header('id.example.net', '/resend', start => 1); |
127 my $fe = http_host_header('fe.example.net', '/resend', start => 1); | 129 my $fe = http_host_header('fe.example.net', '/resend', start => 1); |
161 | 163 |
162 # many A records in round robin | 164 # many A records in round robin |
163 # nonexisting IPs enumerated with proxy_next_upstream | 165 # nonexisting IPs enumerated with proxy_next_upstream |
164 | 166 |
165 like(http_host_header('many.example.net', '/'), | 167 like(http_host_header('many.example.net', '/'), |
166 qr/^127.0.0.20(1:8080, 127.0.0.202:8080|2:8080, 127.0.0.201:8080)$/m, | 168 qr/^127.0.0.20(1:$p0, 127.0.0.202:$p0|2:$p0, 127.0.0.201:$p0)$/m, |
167 'A many'); | 169 'A many'); |
168 | 170 |
169 like(http_host_header('many.example.net', '/'), | 171 like(http_host_header('many.example.net', '/'), |
170 qr/^127.0.0.20(1:8080, 127.0.0.202:8080|2:8080, 127.0.0.201:8080)$/m, | 172 qr/^127.0.0.20(1:$p0, 127.0.0.202:$p0|2:$p0, 127.0.0.201:$p0)$/m, |
171 'A many cached'); | 173 'A many cached'); |
172 | 174 |
173 # tests for several resolvers specified in directive | 175 # tests for several resolvers specified in directive |
174 # query bad ns, make sure that error responses are not cached | 176 # query bad ns, make sure that error responses are not cached |
175 | 177 |
481 } | 483 } |
482 | 484 |
483 push @rdata, rd_addr(0, '127.0.0.1'); | 485 push @rdata, rd_addr(0, '127.0.0.1'); |
484 | 486 |
485 } elsif ($name eq '2.example.net') { | 487 } elsif ($name eq '2.example.net') { |
486 if ($port == 8081) { | 488 if ($port == port(1)) { |
487 $state->{twocnt}++; | 489 $state->{twocnt}++; |
488 } | 490 } |
489 if ($state->{twocnt} & 1) { | 491 if ($state->{twocnt} & 1) { |
490 $rcode = SERVFAIL; | 492 $rcode = SERVFAIL; |
491 } | 493 } |
493 if ($type == A) { | 495 if ($type == A) { |
494 push @rdata, rd_addr($ttl, '127.0.0.1'); | 496 push @rdata, rd_addr($ttl, '127.0.0.1'); |
495 } | 497 } |
496 | 498 |
497 } elsif ($name =~ /tcp2?.example.net/) { | 499 } elsif ($name =~ /tcp2?.example.net/) { |
498 $rcode = FORMERR if $port == 8082; | 500 $rcode = FORMERR if $port == port(2); |
499 $hdr |= 0x0300 unless $extra{tcp}; | 501 $hdr |= 0x0300 unless $extra{tcp}; |
500 push @rdata, rd_addr($ttl, $extra{tcp} | 502 push @rdata, rd_addr($ttl, $extra{tcp} |
501 ? '127.0.0.1' : '127.0.0.201') if $type == A; | 503 ? '127.0.0.1' : '127.0.0.201') if $type == A; |
502 } | 504 } |
503 | 505 |
529 | 531 |
530 my $sel = IO::Select->new($socket); | 532 my $sel = IO::Select->new($socket); |
531 my $tcp = 0; | 533 my $tcp = 0; |
532 | 534 |
533 if ($extra{tcp}) { | 535 if ($extra{tcp}) { |
534 $tcp = IO::Socket::INET->new( | 536 $tcp = port(3, socket => 1)->listen(); |
535 Proto => 'tcp', | |
536 LocalHost => "127.0.0.1:$port", | |
537 Listen => 5, | |
538 Reuse => 1 | |
539 ) | |
540 or die "Can't create listening socket: $!\n"; | |
541 | |
542 $sel->add($tcp); | 537 $sel->add($tcp); |
543 } | 538 } |
544 | 539 |
545 local $SIG{PIPE} = 'IGNORE'; | 540 local $SIG{PIPE} = 'IGNORE'; |
546 | 541 |