Mercurial > hg > nginx-tests
comparison http_resolver_aaaa.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 | 882267679006 |
comparison
equal
deleted
inserted
replaced
951:9361c7eddfc1 | 952:e9064d691790 |
---|---|
35 | 35 |
36 http { | 36 http { |
37 %%TEST_GLOBALS_HTTP%% | 37 %%TEST_GLOBALS_HTTP%% |
38 | 38 |
39 server { | 39 server { |
40 listen 127.0.0.1:8080; | 40 listen 127.0.0.1:%%PORT_0%%; |
41 listen [::1]:8080; | 41 listen [::1]:%%PORT_0%%; |
42 server_name localhost; | 42 server_name localhost; |
43 | 43 |
44 location / { | 44 location / { |
45 resolver 127.0.0.1:8081; | 45 resolver 127.0.0.1:%%PORT_1_UDP%%; |
46 proxy_pass http://$host:8080/backend; | 46 proxy_pass http://$host:%%PORT_0%%/backend; |
47 | 47 |
48 proxy_next_upstream http_504 timeout error; | 48 proxy_next_upstream http_504 timeout error; |
49 proxy_intercept_errors on; | 49 proxy_intercept_errors on; |
50 proxy_connect_timeout 50ms; | 50 proxy_connect_timeout 50ms; |
51 error_page 504 502 /50x; | 51 error_page 504 502 /50x; |
52 add_header X-Host $upstream_addr; | 52 add_header X-Host $upstream_addr; |
53 } | 53 } |
54 location /two { | 54 location /two { |
55 resolver 127.0.0.1:8081 127.0.0.1:8082; | 55 resolver 127.0.0.1:%%PORT_1_UDP%% 127.0.0.1:%%PORT_2_UDP%%; |
56 proxy_pass http://$host:8080/backend; | 56 proxy_pass http://$host:%%PORT_0%%/backend; |
57 } | 57 } |
58 | 58 |
59 location /backend { | 59 location /backend { |
60 return 200; | 60 return 200; |
61 } | 61 } |
67 | 67 |
68 EOF | 68 EOF |
69 | 69 |
70 $t->try_run('no inet6 support')->plan(72); | 70 $t->try_run('no inet6 support')->plan(72); |
71 | 71 |
72 $t->run_daemon(\&dns_daemon, 8081, $t); | 72 $t->run_daemon(\&dns_daemon, port(1), $t); |
73 $t->run_daemon(\&dns_daemon, 8082, $t); | 73 $t->run_daemon(\&dns_daemon, port(2), $t); |
74 | 74 |
75 $t->waitforfile($t->testdir . '/8081'); | 75 $t->waitforfile($t->testdir . '/' . port(1)); |
76 $t->waitforfile($t->testdir . '/8082'); | 76 $t->waitforfile($t->testdir . '/' . port(2)); |
77 | 77 |
78 ############################################################################### | 78 ############################################################################### |
79 | 79 |
80 my (@n, $response); | 80 my (@n, $response); |
81 | |
82 my $p0 = port(0); | |
81 | 83 |
82 like(http_host_header('aaaa.example.net', '/'), qr/\[fe80::1\]/, 'AAAA'); | 84 like(http_host_header('aaaa.example.net', '/'), qr/\[fe80::1\]/, 'AAAA'); |
83 like(http_host_header('cname.example.net', '/'), qr/\[fe80::1\]/, 'CNAME'); | 85 like(http_host_header('cname.example.net', '/'), qr/\[fe80::1\]/, 'CNAME'); |
84 like(http_host_header('cname.example.net', '/'), qr/\[fe80::1\]/, | 86 like(http_host_header('cname.example.net', '/'), qr/\[fe80::1\]/, |
85 'CNAME cached'); | 87 'CNAME cached'); |
91 | 93 |
92 # many AAAA records in round robin | 94 # many AAAA records in round robin |
93 # nonexisting IPs enumerated with proxy_next_upstream | 95 # nonexisting IPs enumerated with proxy_next_upstream |
94 | 96 |
95 like(http_host_header('many.example.net', '/'), | 97 like(http_host_header('many.example.net', '/'), |
96 qr/^\[fe80::(1\]:8080, \[fe80::2\]:8080|2\]:8080, \[fe80::1\]:8080)$/m, | 98 qr/^\[fe80::(1\]:$p0, \[fe80::2\]:$p0|2\]:$p0, \[fe80::1\]:$p0)$/m, |
97 'AAAA many'); | 99 'AAAA many'); |
98 | 100 |
99 like(http_host_header('many.example.net', '/'), | 101 like(http_host_header('many.example.net', '/'), |
100 qr/^\[fe80::(1\]:8080, \[fe80::2\]:8080|2\]:8080, \[fe80::1\]:8080)$/m, | 102 qr/^\[fe80::(1\]:$p0, \[fe80::2\]:$p0|2\]:$p0, \[fe80::1\]:$p0)$/m, |
101 'AAAA many cached'); | 103 'AAAA many cached'); |
102 | 104 |
103 # tests for several resolvers specified in directive | 105 # tests for several resolvers specified in directive |
104 # query bad ns, make sure that error responses are not cached | 106 # query bad ns, make sure that error responses are not cached |
105 | 107 |
114 like(http_host_header('2.example.net', '/two'), qr/200 OK/, 'two ns cached'); | 116 like(http_host_header('2.example.net', '/two'), qr/200 OK/, 'two ns cached'); |
115 | 117 |
116 # various ipv4/ipv6 combinations | 118 # various ipv4/ipv6 combinations |
117 | 119 |
118 $response = http_host_header('z_z.example.net', '/'); | 120 $response = http_host_header('z_z.example.net', '/'); |
119 is(@n = $response =~ /8080/g, 0, 'zero zero responses'); | 121 is(@n = $response =~ /$p0/g, 0, 'zero zero responses'); |
120 like($response, qr/502 Bad/, 'zero zero'); | 122 like($response, qr/502 Bad/, 'zero zero'); |
121 | 123 |
122 like(http_host_header('z_n.example.net', '/'), qr/^\[fe80::1\]:8080$/ms, | 124 like(http_host_header('z_n.example.net', '/'), qr/^\[fe80::1\]:$p0$/ms, |
123 'zero AAAA'); | 125 'zero AAAA'); |
124 | 126 |
125 $response = http_host_header('z_c.example.net', '/'); | 127 $response = http_host_header('z_c.example.net', '/'); |
126 is(@n = $response =~ /8080/g, 2, 'zero CNAME responses'); | 128 is(@n = $response =~ /$p0/g, 2, 'zero CNAME responses'); |
127 like($response, qr/127.0.0.201:8080/, 'zero CNAME 1'); | 129 like($response, qr/127.0.0.201:$p0/, 'zero CNAME 1'); |
128 like($response, qr/\[fe80::1\]:8080/, 'zero CNAME 2'); | 130 like($response, qr/\[fe80::1\]:$p0/, 'zero CNAME 2'); |
129 | 131 |
130 $response = http_host_header('z_cn.example.net', '/'); | 132 $response = http_host_header('z_cn.example.net', '/'); |
131 is(@n = $response =~ /8080/g, 2, 'zero CNAME+AAAA responses'); | 133 is(@n = $response =~ /$p0/g, 2, 'zero CNAME+AAAA responses'); |
132 like($response, qr/\[fe80::1\]:8080/, 'zero CNAME+AAAA 1'); | 134 like($response, qr/\[fe80::1\]:$p0/, 'zero CNAME+AAAA 1'); |
133 like($response, qr/\[fe80::2\]:8080/, 'zero CNAME+AAAA 2'); | 135 like($response, qr/\[fe80::2\]:$p0/, 'zero CNAME+AAAA 2'); |
134 | 136 |
135 $response = http_host_header('z_e.example.net', '/'); | 137 $response = http_host_header('z_e.example.net', '/'); |
136 is(@n = $response =~ /8080/g, 0, 'zero error responses'); | 138 is(@n = $response =~ /$p0/g, 0, 'zero error responses'); |
137 like($response, qr/502 Bad/, 'zero error'); | 139 like($response, qr/502 Bad/, 'zero error'); |
138 | 140 |
139 like(http_host_header('n_z.example.net', '/'), qr/^127.0.0.201:8080$/ms, | 141 like(http_host_header('n_z.example.net', '/'), qr/^127.0.0.201:$p0$/ms, |
140 'A zero'); | 142 'A zero'); |
141 | 143 |
142 $response = http_host_header('n_n.example.net', '/'); | 144 $response = http_host_header('n_n.example.net', '/'); |
143 is(@n = $response =~ /8080/g, 2, 'A AAAA responses'); | 145 is(@n = $response =~ /$p0/g, 2, 'A AAAA responses'); |
144 like($response, qr/127.0.0.201:8080/, 'A AAAA 1'); | 146 like($response, qr/127.0.0.201:$p0/, 'A AAAA 1'); |
145 like($response, qr/\[fe80::1\]:8080/, 'A AAAA 2'); | 147 like($response, qr/\[fe80::1\]:$p0/, 'A AAAA 2'); |
146 | 148 |
147 like(http_host_header('n_c.example.net', '/'), qr/^127.0.0.201:8080$/ms, | 149 like(http_host_header('n_c.example.net', '/'), qr/^127.0.0.201:$p0$/ms, |
148 'A CNAME'); | 150 'A CNAME'); |
149 | 151 |
150 $response = http_host_header('n_cn.example.net', '/'); | 152 $response = http_host_header('n_cn.example.net', '/'); |
151 is(@n = $response =~ /8080/g, 4, 'A CNAME+AAAA responses'); | 153 is(@n = $response =~ /$p0/g, 4, 'A CNAME+AAAA responses'); |
152 like($response, qr/127.0.0.201:8080/, 'A CNAME+AAAA 1'); | 154 like($response, qr/127.0.0.201:$p0/, 'A CNAME+AAAA 1'); |
153 like($response, qr/127.0.0.202:8080/, 'A CNAME+AAAA 2'); | 155 like($response, qr/127.0.0.202:$p0/, 'A CNAME+AAAA 2'); |
154 like($response, qr/\[fe80::1\]:8080/, 'A CNAME+AAAA 3'); | 156 like($response, qr/\[fe80::1\]:$p0/, 'A CNAME+AAAA 3'); |
155 like($response, qr/\[fe80::2\]:8080/, 'A CNAME+AAAA 4'); | 157 like($response, qr/\[fe80::2\]:$p0/, 'A CNAME+AAAA 4'); |
156 | 158 |
157 $response = http_host_header('n_e.example.net', '/'); | 159 $response = http_host_header('n_e.example.net', '/'); |
158 is(@n = $response =~ /8080/g, 0, 'A error responses'); | 160 is(@n = $response =~ /$p0/g, 0, 'A error responses'); |
159 like($response, qr/502 Bad/, 'A error'); | 161 like($response, qr/502 Bad/, 'A error'); |
160 | 162 |
161 $response = http_host_header('c_z.example.net', '/'); | 163 $response = http_host_header('c_z.example.net', '/'); |
162 is(@n = $response =~ /8080/g, 0, 'CNAME zero responses'); | 164 is(@n = $response =~ /$p0/g, 0, 'CNAME zero responses'); |
163 like($response, qr/502 Bad/, 'CNAME zero'); | 165 like($response, qr/502 Bad/, 'CNAME zero'); |
164 | 166 |
165 like(http_host_header('c_n.example.net', '/'), qr/^\[fe80::1\]:8080$/ms, | 167 like(http_host_header('c_n.example.net', '/'), qr/^\[fe80::1\]:$p0$/ms, |
166 'CNAME AAAA'); | 168 'CNAME AAAA'); |
167 | 169 |
168 $response = http_host_header('c_c.example.net', '/'); | 170 $response = http_host_header('c_c.example.net', '/'); |
169 is(@n = $response =~ /8080/g, 2, 'CNAME CNAME responses'); | 171 is(@n = $response =~ /$p0/g, 2, 'CNAME CNAME responses'); |
170 like($response, qr/127.0.0.201:8080/, 'CNAME CNAME 1'); | 172 like($response, qr/127.0.0.201:$p0/, 'CNAME CNAME 1'); |
171 like($response, qr/\[fe80::1\]:8080/, 'CNAME CNAME 2'); | 173 like($response, qr/\[fe80::1\]:$p0/, 'CNAME CNAME 2'); |
172 | 174 |
173 like(http_host_header('c1_c2.example.net', '/'), qr/^\[fe80::1\]:8080$/ms, | 175 like(http_host_header('c1_c2.example.net', '/'), qr/^\[fe80::1\]:$p0$/ms, |
174 'CNAME1 CNAME2'); | 176 'CNAME1 CNAME2'); |
175 | 177 |
176 $response = http_host_header('c_cn.example.net', '/'); | 178 $response = http_host_header('c_cn.example.net', '/'); |
177 is(@n = $response =~ /8080/g, 2, 'CNAME CNAME+AAAA responses'); | 179 is(@n = $response =~ /$p0/g, 2, 'CNAME CNAME+AAAA responses'); |
178 like($response, qr/\[fe80::1\]:8080/, 'CNAME CNAME+AAAA 1'); | 180 like($response, qr/\[fe80::1\]:$p0/, 'CNAME CNAME+AAAA 1'); |
179 like($response, qr/\[fe80::2\]:8080/, 'CNAME CNAME+AAAA 1'); | 181 like($response, qr/\[fe80::2\]:$p0/, 'CNAME CNAME+AAAA 1'); |
180 | 182 |
181 $response = http_host_header('c_e.example.net', '/'); | 183 $response = http_host_header('c_e.example.net', '/'); |
182 is(@n = $response =~ /8080/g, 0, 'CNAME error responses'); | 184 is(@n = $response =~ /$p0/g, 0, 'CNAME error responses'); |
183 like($response, qr/502 Bad/, 'CNAME error'); | 185 like($response, qr/502 Bad/, 'CNAME error'); |
184 | 186 |
185 $response = http_host_header('cn_z.example.net', '/'); | 187 $response = http_host_header('cn_z.example.net', '/'); |
186 is(@n = $response =~ /8080/g, 2, 'CNAME+A zero responses'); | 188 is(@n = $response =~ /$p0/g, 2, 'CNAME+A zero responses'); |
187 like($response, qr/127.0.0.201:8080/, 'CNAME+A zero 1'); | 189 like($response, qr/127.0.0.201:$p0/, 'CNAME+A zero 1'); |
188 like($response, qr/127.0.0.202:8080/, 'CNAME+A zero 2'); | 190 like($response, qr/127.0.0.202:$p0/, 'CNAME+A zero 2'); |
189 | 191 |
190 $response = http_host_header('cn_n.example.net', '/'); | 192 $response = http_host_header('cn_n.example.net', '/'); |
191 is(@n = $response =~ /8080/g, 4, 'CNAME+A AAAA responses'); | 193 is(@n = $response =~ /$p0/g, 4, 'CNAME+A AAAA responses'); |
192 like($response, qr/127.0.0.201:8080/, 'CNAME+A AAAA 1'); | 194 like($response, qr/127.0.0.201:$p0/, 'CNAME+A AAAA 1'); |
193 like($response, qr/127.0.0.202:8080/, 'CNAME+A AAAA 2'); | 195 like($response, qr/127.0.0.202:$p0/, 'CNAME+A AAAA 2'); |
194 like($response, qr/\[fe80::1\]:8080/, 'CNAME+A AAAA 3'); | 196 like($response, qr/\[fe80::1\]:$p0/, 'CNAME+A AAAA 3'); |
195 like($response, qr/\[fe80::2\]:8080/, 'CNAME+A AAAA 4'); | 197 like($response, qr/\[fe80::2\]:$p0/, 'CNAME+A AAAA 4'); |
196 | 198 |
197 $response = http_host_header('cn_c.example.net', '/'); | 199 $response = http_host_header('cn_c.example.net', '/'); |
198 is(@n = $response =~ /8080/g, 2, 'CNAME+A CNAME responses'); | 200 is(@n = $response =~ /$p0/g, 2, 'CNAME+A CNAME responses'); |
199 like($response, qr/127.0.0.201:8080/, 'CNAME+A CNAME 1'); | 201 like($response, qr/127.0.0.201:$p0/, 'CNAME+A CNAME 1'); |
200 like($response, qr/127.0.0.202:8080/, 'CNAME+A CNAME 2'); | 202 like($response, qr/127.0.0.202:$p0/, 'CNAME+A CNAME 2'); |
201 | 203 |
202 $response = http_host_header('cn_cn.example.net', '/'); | 204 $response = http_host_header('cn_cn.example.net', '/'); |
203 is(@n = $response =~ /8080/g, 4, 'CNAME+A CNAME+AAAA responses'); | 205 is(@n = $response =~ /$p0/g, 4, 'CNAME+A CNAME+AAAA responses'); |
204 like($response, qr/127.0.0.201:8080/, 'CNAME+A CNAME+AAAA 1'); | 206 like($response, qr/127.0.0.201:$p0/, 'CNAME+A CNAME+AAAA 1'); |
205 like($response, qr/127.0.0.202:8080/, 'CNAME+A CNAME+AAAA 2'); | 207 like($response, qr/127.0.0.202:$p0/, 'CNAME+A CNAME+AAAA 2'); |
206 like($response, qr/\[fe80::1\]:8080/, 'CNAME+A CNAME+AAAA 3'); | 208 like($response, qr/\[fe80::1\]:$p0/, 'CNAME+A CNAME+AAAA 3'); |
207 like($response, qr/\[fe80::2\]:8080/, 'CNAME+A CNAME+AAAA 4'); | 209 like($response, qr/\[fe80::2\]:$p0/, 'CNAME+A CNAME+AAAA 4'); |
208 | 210 |
209 $response = http_host_header('cn_e.example.net', '/'); | 211 $response = http_host_header('cn_e.example.net', '/'); |
210 is(@n = $response =~ /8080/g, 0, 'CNAME+A error responses'); | 212 is(@n = $response =~ /$p0/g, 0, 'CNAME+A error responses'); |
211 like($response, qr/502 Bad/, 'CNAME+A error'); | 213 like($response, qr/502 Bad/, 'CNAME+A error'); |
212 | 214 |
213 $response = http_host_header('e_z.example.net', '/'); | 215 $response = http_host_header('e_z.example.net', '/'); |
214 is(@n = $response =~ /8080/g, 0, 'error zero responses'); | 216 is(@n = $response =~ /$p0/g, 0, 'error zero responses'); |
215 like($response, qr/502 Bad/, 'error zero'); | 217 like($response, qr/502 Bad/, 'error zero'); |
216 | 218 |
217 $response = http_host_header('e_n.example.net', '/'); | 219 $response = http_host_header('e_n.example.net', '/'); |
218 is(@n = $response =~ /8080/g, 0, 'error AAAA responses'); | 220 is(@n = $response =~ /$p0/g, 0, 'error AAAA responses'); |
219 like($response, qr/502 Bad/, 'error AAAA'); | 221 like($response, qr/502 Bad/, 'error AAAA'); |
220 | 222 |
221 $response = http_host_header('e_c.example.net', '/'); | 223 $response = http_host_header('e_c.example.net', '/'); |
222 is(@n = $response =~ /8080/g, 0, 'error CNAME responses'); | 224 is(@n = $response =~ /$p0/g, 0, 'error CNAME responses'); |
223 like($response, qr/502 Bad/, 'error CNAME'); | 225 like($response, qr/502 Bad/, 'error CNAME'); |
224 | 226 |
225 $response = http_host_header('e_cn.example.net', '/'); | 227 $response = http_host_header('e_cn.example.net', '/'); |
226 is(@n = $response =~ /8080/g, 0, 'error CNAME+AAAA responses'); | 228 is(@n = $response =~ /$p0/g, 0, 'error CNAME+AAAA responses'); |
227 like($response, qr/502 Bad/, 'error CNAME+AAAA'); | 229 like($response, qr/502 Bad/, 'error CNAME+AAAA'); |
228 | 230 |
229 $response = http_host_header('e_e.example.net', '/'); | 231 $response = http_host_header('e_e.example.net', '/'); |
230 is(@n = $response =~ /8080/g, 0, 'error error responses'); | 232 is(@n = $response =~ /$p0/g, 0, 'error error responses'); |
231 like($response, qr/502 Bad/, 'error error'); | 233 like($response, qr/502 Bad/, 'error error'); |
232 | 234 |
233 ############################################################################### | 235 ############################################################################### |
234 | 236 |
235 sub http_host_header { | 237 sub http_host_header { |
328 push @rdata, pack('n3N nn8', 0xc031, AAAA, IN, $ttl, | 330 push @rdata, pack('n3N nn8', 0xc031, AAAA, IN, $ttl, |
329 16, expand_ip6("::1")); | 331 16, expand_ip6("::1")); |
330 } | 332 } |
331 | 333 |
332 } elsif ($name eq '2.example.net') { | 334 } elsif ($name eq '2.example.net') { |
333 if ($port == 8081) { | 335 if ($port == port(1)) { |
334 $state->{twocnt}++; | 336 $state->{twocnt}++; |
335 } | 337 } |
336 if ($state->{twocnt} & 1) { | 338 if ($state->{twocnt} & 1) { |
337 $rcode = SERVFAIL; | 339 $rcode = SERVFAIL; |
338 } | 340 } |