# HG changeset patch # User Sergey Kandaurov # Date 1705918272 -14400 # Node ID 1786f49cca17a0c942281e28ecb88d276b7dab40 # Parent 00124c7d0ef16ef96628e6712e90c0736ee5bf4f Tests: fixed spurious http_resolver_ipv4.t failures. Previously, to get resolved addresses, the test relied on cached random rotation in resolver, such that a chosen address is eventually changed, which may not happen after several client requests. For this reason, the test is rewritten to get all addresses by switching to the next upstream. diff --git a/http_resolver_ipv4.t b/http_resolver_ipv4.t --- a/http_resolver_ipv4.t +++ b/http_resolver_ipv4.t @@ -23,7 +23,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http proxy rewrite/); +my $t = Test::Nginx->new()->has(qw/http proxy/); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -41,6 +41,9 @@ http { listen 127.0.0.1:8080; server_name localhost; + add_header X-Addr $upstream_addr always; + proxy_next_upstream http_403; + location / { proxy_pass http://$arg_h:%%PORT_8081%%/; resolver 127.0.0.1:%%PORT_8980_UDP%% ipv4=on ipv6=on; @@ -59,19 +62,11 @@ http { server { listen 127.0.0.1:8081; - server_name localhost; - - location / { - return 200 "ipv4"; - } - } - - server { listen [::1]:%%PORT_8081%%; server_name localhost; location / { - return 200 "ipv6"; + # return 403; } } } @@ -85,24 +80,18 @@ EOF ############################################################################### -like(many('/', 10), qr/ipv4: \d+, ipv6: \d+/, 'ipv4 ipv6'); -is(many('/ipv4', 10), 'ipv4: 10', 'ipv4 only'); -is(many('/ipv6', 10), 'ipv6: 10', 'ipv6 only'); +is(get('/'), '127.0.0.1:8081, [::1]:8081', 'ipv4 ipv6'); +is(get('/ipv4'), '127.0.0.1:8081', 'ipv4 only'); +is(get('/ipv6'), '[::1]:8081', 'ipv6 only'); ############################################################################### -sub many { - my ($uri, $count) = @_; - my %hits; +sub get { + my ($uri) = @_; - for (1 .. $count) { - if (http_get("$uri?h=example.com") =~ /(ipv(4|6))/) {; - $hits{$1} = 0 unless defined $hits{$1}; - $hits{$1}++; - } - } - - return join ', ', map { $_ . ": " . $hits{$_} } sort keys %hits; + my $r = http_get("$uri?h=example.com"); + my ($addr) = $r =~ /X-Addr: (.+)\x0d/m; + return $addr; } ###############################################################################