Mercurial > hg > nginx-tests
diff 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 |
line wrap: on
line diff
--- a/http_resolver.t Tue Jun 21 16:37:58 2016 +0300 +++ b/http_resolver.t Tue Jun 21 16:39:13 2016 +0300 @@ -39,13 +39,13 @@ %%TEST_GLOBALS_HTTP%% server { - listen 127.0.0.1:8080; + listen 127.0.0.1:%%PORT_0%%; server_name localhost; location / { - resolver 127.0.0.1:8081; + resolver 127.0.0.1:%%PORT_1_UDP%%; resolver_timeout 1s; - proxy_pass http://$host:8080/backend; + proxy_pass http://$host:%%PORT_0%%/backend; proxy_next_upstream http_504 timeout error; proxy_intercept_errors on; @@ -53,46 +53,46 @@ error_page 504 502 /50x; } location /two { - resolver 127.0.0.1:8081 127.0.0.1:8082; - proxy_pass http://$host:8080/backend; + resolver 127.0.0.1:%%PORT_1_UDP%% 127.0.0.1:%%PORT_2_UDP%%; + proxy_pass http://$host:%%PORT_0%%/backend; } location /valid { - resolver 127.0.0.1:8081 valid=5s; - proxy_pass http://$host:8080/backend; + resolver 127.0.0.1:%%PORT_1_UDP%% valid=5s; + proxy_pass http://$host:%%PORT_0%%/backend; } location /case { - resolver 127.0.0.1:8081; - proxy_pass http://$http_x_name:8080/backend; + resolver 127.0.0.1:%%PORT_1_UDP%%; + proxy_pass http://$http_x_name:%%PORT_0%%/backend; } location /invalid { - proxy_pass http://$host:8080/backend; + proxy_pass http://$host:%%PORT_0%%/backend; } location /long { - resolver 127.0.0.1:8081; + resolver 127.0.0.1:%%PORT_1_UDP%%; resolver_timeout 4s; - proxy_pass http://$host:8080/backend; + proxy_pass http://$host:%%PORT_0%%/backend; } location /resend { - resolver 127.0.0.1:8081; + resolver 127.0.0.1:%%PORT_1_UDP%%; resolver_timeout 8s; - proxy_pass http://$host:8080/backend; + proxy_pass http://$host:%%PORT_0%%/backend; } location /bad { - resolver 127.0.0.1:8089; + resolver 127.0.0.1:%%PORT_4_UDP%%; resolver_timeout 1s; - proxy_pass http://$host:8080/backend; + proxy_pass http://$host:%%PORT_0%%/backend; } location /tcp { - resolver 127.0.0.1:8083 127.0.0.1:8082; + resolver 127.0.0.1:%%PORT_3_UDP%% 127.0.0.1:%%PORT_2_UDP%%; resolver_timeout 1s; - proxy_pass http://$host:8080/backend; + proxy_pass http://$host:%%PORT_0%%/backend; proxy_connect_timeout 1s; add_header X-IP $upstream_addr; error_page 504 502 /50x; location /tcp2 { resolver_timeout 8s; - proxy_pass http://$host:8080/backend; + proxy_pass http://$host:%%PORT_0%%/backend; } } @@ -107,20 +107,22 @@ EOF -$t->run_daemon(\&dns_daemon, 8081, $t); -$t->run_daemon(\&dns_daemon, 8082, $t); -$t->run_daemon(\&dns_daemon, 8083, $t, tcp => 1); -$t->run_daemon(\&dns_daemon, 8089, $t); +$t->run_daemon(\&dns_daemon, port(1), $t); +$t->run_daemon(\&dns_daemon, port(2), $t); +$t->run_daemon(\&dns_daemon, port(3), $t, tcp => 1); +$t->run_daemon(\&dns_daemon, port(4), $t); $t->run()->plan(38); -$t->waitforfile($t->testdir . '/8081'); -$t->waitforfile($t->testdir . '/8082'); -$t->waitforfile($t->testdir . '/8083'); -$t->waitforfile($t->testdir . '/8089'); +$t->waitforfile($t->testdir . '/' . port(1)); +$t->waitforfile($t->testdir . '/' . port(2)); +$t->waitforfile($t->testdir . '/' . port(3)); +$t->waitforfile($t->testdir . '/' . port(4)); ############################################################################### +my $p0 = port(0); + # schedule resend test, which takes about 5 seconds to complete my $s = http_host_header('id.example.net', '/resend', start => 1); @@ -163,11 +165,11 @@ # nonexisting IPs enumerated with proxy_next_upstream like(http_host_header('many.example.net', '/'), - qr/^127.0.0.20(1:8080, 127.0.0.202:8080|2:8080, 127.0.0.201:8080)$/m, + qr/^127.0.0.20(1:$p0, 127.0.0.202:$p0|2:$p0, 127.0.0.201:$p0)$/m, 'A many'); like(http_host_header('many.example.net', '/'), - qr/^127.0.0.20(1:8080, 127.0.0.202:8080|2:8080, 127.0.0.201:8080)$/m, + qr/^127.0.0.20(1:$p0, 127.0.0.202:$p0|2:$p0, 127.0.0.201:$p0)$/m, 'A many cached'); # tests for several resolvers specified in directive @@ -483,7 +485,7 @@ push @rdata, rd_addr(0, '127.0.0.1'); } elsif ($name eq '2.example.net') { - if ($port == 8081) { + if ($port == port(1)) { $state->{twocnt}++; } if ($state->{twocnt} & 1) { @@ -495,7 +497,7 @@ } } elsif ($name =~ /tcp2?.example.net/) { - $rcode = FORMERR if $port == 8082; + $rcode = FORMERR if $port == port(2); $hdr |= 0x0300 unless $extra{tcp}; push @rdata, rd_addr($ttl, $extra{tcp} ? '127.0.0.1' : '127.0.0.201') if $type == A; @@ -531,14 +533,7 @@ my $tcp = 0; if ($extra{tcp}) { - $tcp = IO::Socket::INET->new( - Proto => 'tcp', - LocalHost => "127.0.0.1:$port", - Listen => 5, - Reuse => 1 - ) - or die "Can't create listening socket: $!\n"; - + $tcp = port(3, socket => 1)->listen(); $sel->add($tcp); }