]> Sergey Matveev's repositories - public-inbox.git/commitdiff
tests: favor IPv6
authorEric Wong <e@80x24.org>
Mon, 8 Feb 2021 09:05:13 +0000 (23:05 -1000)
committerEric Wong <e@80x24.org>
Mon, 8 Feb 2021 22:07:43 +0000 (22:07 +0000)
IPv4 gets plenty of real-world coverage, and apparently there's
Debian buildd hosts which lack IPv4(*).  So ensure everything
can work on IPv6 and not cause problems for odd setups.

(*) https://bugs.debian.org/979432

27 files changed:
lib/PublicInbox/TestCommon.pm
t/extsearch.t
t/httpd-corner.psgi
t/httpd-corner.t
t/httpd-https.t
t/httpd-unix.t
t/httpd.t
t/imapd-tls.t
t/imapd.t
t/lei-mirror.t
t/nntpd-tls.t
t/nntpd.t
t/psgi_attach.t
t/psgi_v2.t
t/solver_git.t
t/v2mirror.t
t/v2writable.t
t/www_altid.t
t/www_listing.t
xt/git-http-backend.t
xt/httpd-async-stream.t
xt/imapd-mbsync-oimap.t
xt/imapd-validate.t
xt/mem-imapd-tls.t
xt/nntpd-validate.t
xt/perf-nntpd.t
xt/solver.t

index 5cce44e42bc1fd23a8ce7dea513628abdfc09f68..2f4ca62255716cd7a0768bb7d44eb894cfe5ff18 100644 (file)
@@ -14,7 +14,7 @@ BEGIN {
        @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
                run_script start_script key2sub xsys xsys_e xqx eml_load tick
                have_xapian_compact json_utf8 setup_public_inboxes
-               test_lei $lei $lei_out $lei_err $lei_opt);
+               tcp_host_port test_lei $lei $lei_out $lei_err $lei_opt);
        require Test::More;
        my @methods = grep(!/\W/, @Test::More::EXPORT);
        eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
@@ -40,20 +40,38 @@ sub tmpdir (;$) {
 }
 
 sub tcp_server () {
-       IO::Socket::INET->new(
-               LocalAddr => '127.0.0.1',
+       my %opt = (
                ReuseAddr => 1,
                Proto => 'tcp',
                Type => Socket::SOCK_STREAM(),
                Listen => 1024,
                Blocking => 0,
-       ) or BAIL_OUT "failed to create TCP server: $!";
+       );
+       eval {
+               die 'IPv4-only' if $ENV{TEST_IPV4_ONLY};
+               require IO::Socket::INET6;
+               IO::Socket::INET6->new(%opt, LocalAddr => '[::1]')
+       } || eval {
+               die 'IPv6-only' if $ENV{TEST_IPV6_ONLY};
+               IO::Socket::INET->new(%opt, LocalAddr => '127.0.0.1')
+       } || BAIL_OUT "failed to create TCP server: $! ($@)";
+}
+
+sub tcp_host_port ($) {
+       my ($s) = @_;
+       my ($h, $p) = ($s->sockhost, $s->sockport);
+       my $ipv4 = $s->sockdomain == Socket::AF_INET();
+       if (wantarray) {
+               $ipv4 ? ($h, $p) : ("[$h]", $p);
+       } else {
+               $ipv4 ? "$h:$p" : "[$h]:$p";
+       }
 }
 
 sub tcp_connect {
        my ($dest, %opt) = @_;
-       my $addr = $dest->sockhost . ':' . $dest->sockport;
-       my $s = IO::Socket::INET->new(
+       my $addr = tcp_host_port($dest);
+       my $s = ref($dest)->new(
                Proto => 'tcp',
                Type => Socket::SOCK_STREAM(),
                PeerAddr => $addr,
index 26c3d4ae72ece18d18297478b77d6ed3e0e5443e..d199fc7b9804055fec9c79f2a79ed1a4d3f7489c 100644 (file)
@@ -14,7 +14,7 @@ use_ok 'PublicInbox::ExtSearch';
 use_ok 'PublicInbox::ExtSearchIdx';
 use_ok 'PublicInbox::OverIdx';
 my $sock = tcp_server();
-my $host_port = $sock->sockhost . ':' . $sock->sockport;
+my $host_port = tcp_host_port($sock);
 my ($home, $for_destroy) = tmpdir();
 local $ENV{HOME} = $home;
 mkdir "$home/.public-inbox" or BAIL_OUT $!;
index 5436a74dc56e71fb8ff87614dac1a462ae4eefe8..5fab2ba48d1e39e05cc6bcff9c0005673661cb2f 100644 (file)
@@ -48,7 +48,7 @@ my $app = sub {
                }
        } elsif ($path eq '/host-port') {
                $code = 200;
-               push @$body, "$env->{REMOTE_ADDR}:$env->{REMOTE_PORT}";
+               push @$body, "$env->{REMOTE_ADDR} $env->{REMOTE_PORT}";
        } elsif ($path eq '/callback') {
                return sub {
                        my ($res) = @_;
index c3f805303f8d2daa50d147639796a3bfc11eb477..794d8aebe7ca0414a22492bb747778784e839723 100644 (file)
@@ -11,7 +11,6 @@ use PublicInbox::TestCommon;
 require_mods(qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status));
 use Digest::SHA qw(sha1_hex);
 use IO::Handle ();
-use IO::Socket;
 use IO::Socket::UNIX;
 use Fcntl qw(:seek);
 use Socket qw(IPPROTO_TCP TCP_NODELAY SOL_SOCKET);
@@ -50,14 +49,13 @@ sub unix_server ($) {
                Listen => 1024,
                Type => Socket::SOCK_STREAM(),
                Local => $_[0],
-       );
+       ) or BAIL_OUT "bind + listen $_[0]: $!";
        $s->blocking(0);
        $s;
 }
 
 my $upath = "$tmpdir/s";
 my $unix = unix_server($upath);
-ok($unix, 'UNIX socket created');
 my $td;
 my $spawn_httpd = sub {
        my (@args) = @_;
@@ -219,7 +217,7 @@ sub check_400 {
        ok($u, 'unix socket connected');
        $u->write("GET /host-port HTTP/1.0\r\n\r\n");
        $u->read(my $buf, 4096);
-       like($buf, qr!\r\n\r\n127\.0\.0\.1:0\z!,
+       like($buf, qr!\r\n\r\n127\.0\.0\.1 0\z!,
                'set REMOTE_ADDR and REMOTE_PORT for Unix socket');
 }
 
@@ -236,8 +234,8 @@ sub conn_for {
        $conn->write("GET /host-port HTTP/1.0\r\n\r\n");
        $conn->read(my $buf, 4096);
        my ($head, $body) = split(/\r\n\r\n/, $buf);
-       my ($addr, $port) = split(/:/, $body);
-       is($addr, $conn->sockhost, 'host matches addr');
+       my ($addr, $port) = split(/ /, $body);
+       is($addr, (tcp_host_port($conn))[0], 'host matches addr');
        is($port, $conn->sockport, 'port matches');
 }
 
@@ -306,7 +304,7 @@ my $check_self = sub {
 
 SKIP: {
        my $curl = which('curl') or skip('curl(1) missing', 4);
-       my $base = 'http://' . $sock->sockhost . ':' . $sock->sockport;
+       my $base = 'http://'.tcp_host_port($sock);
        my $url = "$base/sha1";
        my ($r, $w);
        pipe($r, $w) or die "pipe: $!";
index a2166ce60a0e48d9ac261a315780828151c2d20e..b37492ebb2908524d41a6ba810d5697b5835135a 100644 (file)
@@ -21,7 +21,7 @@ my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
 my $https = tcp_server();
 my $td;
-my $https_addr = $https->sockhost . ':' . $https->sockport;
+my $https_addr = tcp_host_port($https);
 
 for my $args (
        [ "-lhttps://$https_addr/?key=$key,cert=$cert" ],
index 2d3cecc121a0b3d3b423ccae03f7ca62e3f0e708..fe4a21616373a682d71020a6be26e7b10b6f76fe 100644 (file)
@@ -42,13 +42,12 @@ for (1..1000) {
 ok(-S $unix, 'UNIX socket was bound by -httpd');
 sub check_sock ($) {
        my ($unix) = @_;
-       my $sock = IO::Socket::UNIX->new(Peer => $unix, Type => SOCK_STREAM);
-       warn "E: $! connecting to $unix\n" unless defined $sock;
-       ok($sock, 'client UNIX socket connected');
+       my $sock = IO::Socket::UNIX->new(Peer => $unix, Type => SOCK_STREAM)
+               // BAIL_OUT "E: $! connecting to $unix";
        ok($sock->write("GET /host-port HTTP/1.0\r\n\r\n"),
                'wrote req to server');
        ok($sock->read(my $buf, 4096), 'read response');
-       like($buf, qr!\r\n\r\n127\.0\.0\.1:0\z!,
+       like($buf, qr!\r\n\r\n127\.0\.0\.1 0\z!,
                'set REMOTE_ADDR and REMOTE_PORT for Unix socket');
 }
 
index 2fc28355e97851f66b8f3adf3f39bb88c9db190e..af9fbfeb2bd317596c08314083e34a0f79ae4444 100644 (file)
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -44,11 +44,9 @@ EOF
                $im->add($mime);
                $im->done($mime);
        }
-       ok($sock, 'sock created');
        $cmd = [ '-httpd', '-W0', "--stdout=$out", "--stderr=$err" ];
        $td = start_script($cmd, undef, { 3 => $sock });
-       my $host = $sock->sockhost;
-       my $port = $sock->sockport;
+       my $http_pfx = 'http://'.tcp_host_port($sock);
        {
                my $bad = tcp_connect($sock);
                print $bad "GETT / HTTP/1.0\r\n\r\n" or die;
@@ -65,7 +63,7 @@ EOF
        }
 
        is(xsys(qw(git clone -q --mirror),
-                       "http://$host:$port/$group", "$tmpdir/clone.git"),
+                       "$http_pfx/$group", "$tmpdir/clone.git"),
                0, 'smart clone successful');
 
        # ensure dumb cloning works, too:
@@ -73,7 +71,7 @@ EOF
                qw(config http.uploadpack false)),
                0, 'disable http.uploadpack');
        is(xsys(qw(git clone -q --mirror),
-                       "http://$host:$port/$group", "$tmpdir/dumb.git"),
+                       "$http_pfx/$group", "$tmpdir/dumb.git"),
                0, 'clone successful');
 
        ok($td->kill, 'killed httpd');
index e40ae1e89715debce15aef9d526751a4b494b89a..ab90ddec4738fb54fae016a6bd2518ac7956fe32 100644 (file)
@@ -70,8 +70,8 @@ EOF
        }
 }
 
-my $imaps_addr = $imaps->sockhost . ':' . $imaps->sockport;
-my $starttls_addr = $starttls->sockhost . ':' . $starttls->sockport;
+my $imaps_addr = tcp_host_port($imaps);
+my $starttls_addr = tcp_host_port($starttls);
 my $env = { PI_CONFIG => $pi_config };
 my $td;
 
index 1df9d26e5dea9190a51c034978795ba4bf1a8901..0583dfdd138b5fa4a7dd92dc50132f00b14c1afe 100644 (file)
--- a/t/imapd.t
+++ b/t/imapd.t
@@ -60,11 +60,8 @@ my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
 my $cmd = [ '-imapd', '-W0', "--stdout=$out", "--stderr=$err" ];
 my $td = start_script($cmd, undef, { 3 => $sock }) or BAIL_OUT("-imapd: $?");
-my %mic_opt = (
-       Server => $sock->sockhost,
-       Port => $sock->sockport,
-       Uid => 1,
-);
+my ($ihost, $iport) = tcp_host_port($sock);
+my %mic_opt = ( Server => $ihost, Port => $iport, Uid => 1 );
 my $mic = $imap_client->new(%mic_opt);
 my $pre_login_capa = $mic->capability;
 is(grep(/\AAUTH=ANONYMOUS\z/, @$pre_login_capa), 1,
@@ -456,7 +453,6 @@ SKIP: {
        my $url = "http://example.com/i1";
        my $inboxdir = "$tmpdir/watchimap";
        my $cmd = ['-init', '-V2', '-Lbasic', $name, $inboxdir, $url, $addr];
-       my ($ihost, $iport) = ($sock->sockhost, $sock->sockport);
        my $imapurl = "imap://$ihost:$iport/inbox.i1.0";
        run_script($cmd) or BAIL_OUT("init $name");
        xsys(qw(git config), "--file=$home/.public-inbox/config",
index 667284fd5bb39b469ed283f7ab0ed842dc173f8e..e3707979d8d16d19fb41f32f7836c38f9e0b603f 100644 (file)
@@ -6,7 +6,7 @@ require_git 2.6;
 require_mods(qw(DBD::SQLite Search::Xapian));
 my $sock = tcp_server();
 my ($tmpdir, $for_destroy) = tmpdir();
-my $http = 'http://'.$sock->sockhost.':'.$sock->sockport.'/';
+my $http = 'http://'.tcp_host_port($sock);
 my ($ro_home, $cfg_path) = setup_public_inboxes;
 my $cmd = [ qw(-httpd -W0), "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ];
 my $td = start_script($cmd, { PI_CONFIG => $cfg_path }, { 3 => $sock });
index 1194be6f18f802a224e810eab0795594e5b76fd6..8dab4ca86bbd47158bd395d7a012368bfb2900b7 100644 (file)
@@ -70,8 +70,8 @@ EOF
        }
 }
 
-my $nntps_addr = $nntps->sockhost . ':' . $nntps->sockport;
-my $starttls_addr = $starttls->sockhost . ':' . $starttls->sockport;
+my $nntps_addr = tcp_host_port($nntps);
+my $starttls_addr = tcp_host_port($starttls);
 my $env = { PI_CONFIG => $pi_config };
 my $td;
 
index 63287d43af49305b8790bcb62fae5e1524f93217..6c100138b262918298c5ced9d872695c197b43d4 100644 (file)
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -8,7 +8,6 @@ use PublicInbox::Spawn qw(which);
 require_mods(qw(DBD::SQLite));
 require PublicInbox::InboxWritable;
 use PublicInbox::Eml;
-use IO::Socket;
 use Socket qw(IPPROTO_TCP TCP_NODELAY);
 use Net::NNTP;
 use Sys::Hostname;
@@ -34,6 +33,7 @@ my $addr = $group . '@example.com';
 
 my %opts;
 my $sock = tcp_server();
+my $host_port = tcp_host_port($sock);
 my $td;
 my $len;
 
@@ -96,10 +96,8 @@ EOF
                }
        }
 
-       ok($sock, 'sock created');
        my $cmd = [ '-nntpd', '-W0', "--stdout=$out", "--stderr=$err" ];
        $td = start_script($cmd, undef, { 3 => $sock });
-       my $host_port = $sock->sockhost . ':' . $sock->sockport;
        my $n = Net::NNTP->new($host_port);
        my $list = $n->list;
        ok(delete $list->{'x.y.z'}, 'deleted x.y.z group');
@@ -376,7 +374,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
                my @of = xqx([$lsof, '-p', $td->{pid}], undef, $noerr);
                is(scalar(grep(/\(deleted\)/, @of)), 0, 'no deleted files');
        };
-       SKIP: { test_watch($tmpdir, $sock, $group) };
+       SKIP: { test_watch($tmpdir, $host_port, $group) };
        {
                setsockopt($s, IPPROTO_TCP, TCP_NODELAY, 1);
                syswrite($s, 'HDR List-id 1-');
@@ -417,7 +415,7 @@ sub read_til_dot {
 }
 
 sub test_watch {
-       my ($tmpdir, $sock, $group) = @_;
+       my ($tmpdir, $host_port, $group) = @_;
        use_ok 'PublicInbox::Watch';
        use_ok 'PublicInbox::InboxIdle';
        use_ok 'PublicInbox::Config';
@@ -432,8 +430,7 @@ sub test_watch {
        my $url = "http://example.com/i1";
        my $inboxdir = "$tmpdir/watchnntp";
        my $cmd = ['-init', '-V1', '-Lbasic', $name, $inboxdir, $url, $addr];
-       my ($ihost, $iport) = ($sock->sockhost, $sock->sockport);
-       my $nntpurl = "nntp://$ihost:$iport/$group";
+       my $nntpurl = "nntp://$host_port/$group";
        run_script($cmd) or BAIL_OUT("init $name");
        xsys(qw(git config), "--file=$home/.public-inbox/config",
                        "publicinbox.$name.watch",
index 65d704bf87b800d15c453f36d0d384e362b2e5d6..f53b75100955bb41f62a9e4768d83424343d26a8 100644 (file)
@@ -116,7 +116,7 @@ SKIP: {
        my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err);
        my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
        my $td = start_script($cmd, $env, { 3 => $sock });
-       my ($h, $p) = ($sock->sockhost, $sock->sockport);
+       my ($h, $p) = tcp_host_port($sock);
        local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
        Plack::Test::ExternalServer::test_psgi(client => $client);
 }
index 7ab60adcc46f00f33cec66b2b64ccbeb4903204a..81355f04b1b0694b0bb30b6023bc107cdedbde0b 100644 (file)
@@ -35,7 +35,7 @@ my $run_httpd = sub {
                my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err);
                my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
                my $td = start_script($cmd, $env, { 3 => $sock });
-               my ($h, $p) = ($sock->sockhost, $sock->sockport);
+               my ($h, $p) = tcp_host_port($sock);
                local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
                Plack::Test::ExternalServer::test_psgi(client => $client);
                $td->join('TERM');
index d03a6f387a38de5daeae65218aef36c76fb8a1de..3ae7259aaffc03bd4182bfe2947fa152e79fa085 100644 (file)
@@ -196,7 +196,7 @@ EOF
                my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err);
                my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
                my $td = start_script($cmd, $env, { 3 => $sock });
-               my ($h, $p) = ($sock->sockhost, $sock->sockport);
+               my ($h, $p) = tcp_host_port($sock);
                local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
                Plack::Test::ExternalServer::test_psgi(client => $client);
        }
index ebad2566605a79dbbc25d2689e67deba4564da66..12e3fcd0403600b891e4868a0ec7fb8e4a81f989 100644 (file)
@@ -64,10 +64,9 @@ $v2w->done;
 $ibx->cleanup;
 
 my $sock = tcp_server();
-ok($sock, 'sock created');
 my $cmd = [ '-httpd', '-W0', "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ];
 my $td = start_script($cmd, undef, { 3 => $sock });
-my ($host, $port) = ($sock->sockhost, $sock->sockport);
+my ($host, $port) = tcp_host_port($sock);
 $sock = undef;
 
 my @cmd;
index f5c8313a55bc6963b050edc99458d6263d236c60..f0fa8a79548daaca8ff120697dfd3b699204756a 100644 (file)
@@ -164,12 +164,11 @@ EOF
        ;
        close $fh or die "close: $!\n";
        my $sock = tcp_server();
-       ok($sock, 'sock created');
        my $len;
        my $cmd = [ '-nntpd', '-W0', "--stdout=$out", "--stderr=$err" ];
        my $env = { PI_CONFIG => $pi_config };
        my $td = start_script($cmd, $env, { 3 => $sock });
-       my $host_port = $sock->sockhost . ':' . $sock->sockport;
+       my $host_port = tcp_host_port($sock);
        my $n = Net::NNTP->new($host_port);
        $n->group($group);
        my $x = $n->xover('1-');
index 14eda030c510b59eb6f24071abaa56c1472a7163..784acc8b1b5906ffffdebf69b945f7345989b2f4 100644 (file)
@@ -76,7 +76,7 @@ SKIP: {
        my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err);
        my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
        my $td = start_script($cmd, $env, { 3 => $sock });
-       my ($h, $p) = ($sock->sockhost, $sock->sockport);
+       my ($h, $p) = tcp_host_port($sock);
        local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
        Plack::Test::ExternalServer::test_psgi(client => $client);
 }
index 1bcbaefbc02328fc4b38e7f1d41865a1d335e440..63ef2eacfd407d510088a6532bc72b34177d5533 100644 (file)
@@ -79,8 +79,7 @@ SKIP: {
        my $cfgfile = "$tmpdir/config";
        my $v2 = "$tmpdir/v2";
        my $sock = tcp_server();
-       ok($sock, 'sock created');
-       my ($host, $port) = ($sock->sockhost, $sock->sockport);
+       my ($host, $port) = tcp_host_port($sock);
        my @clone = qw(git clone -q -s --bare);
        is(xsys(@clone, $bare->{git_dir}, $alt), 0, 'clone shared repo');
 
index dcff72cc3389058fd374a73205f2f01b48eb9943..adadebb0a15ab7926923d736d5ea34c1282262c2 100644 (file)
@@ -19,8 +19,7 @@ my ($tmpdir, $for_destroy) = tmpdir();
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
 my $sock = tcp_server();
-my $host = $sock->sockhost;
-my $port = $sock->sockport;
+my ($host, $port) = tcp_host_port($sock);
 my $td;
 
 my $get_maxrss = sub {
@@ -37,7 +36,6 @@ my $get_maxrss = sub {
 };
 
 {
-       ok($sock, 'sock created');
        my $cmd = [ '-httpd', '-W0', "--stdout=$out", "--stderr=$err", $psgi ];
        $td = start_script($cmd, undef, { 3 => $sock });
 }
index f6715c58bc31d97476aa2ee4b20918191b73c0cc..c7039f3e86f31ad93f78933fe724a25f442dc734 100644 (file)
@@ -41,7 +41,7 @@ address = test\@example.com
        # not using multiple workers, here, since we want to increase
        # the chance of tripping concurrency bugs within PublicInbox/HTTP*.pm
        my $cmd = [ '-httpd', "--stdout=$out", "--stderr=$err", '-W0' ];
-       my $host_port = $http->sockhost.':'.$http->sockport;
+       my $host_port = tcp_host_port($http);
        push @$cmd, "-lhttp://$host_port";
        my $url = "$host_port/test/$endpoint";
        print STDERR "# CMD ". join(' ', @$cmd). "\n";
index 5f671fc8c8dd18d537b3297caf62115e3450ee35..6635e2b477ee80381dd64118f5bb5bd1f4f5757b 100644 (file)
@@ -35,6 +35,8 @@ my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT "-imapd: $?";
        my $c = tcp_connect($sock);
        like(readline($c), qr/CAPABILITY /, 'got greeting');
 }
+
+my $host_port = tcp_host_port($sock);
 my ($host, $port) = ($sock->sockhost, $sock->sockport);
 my %pids;
 
@@ -120,7 +122,7 @@ while (scalar keys %pids) {
 my $sec = $ENV{TEST_PERSIST} // 0;
 diag "TEST_PERSIST=$sec";
 if ($sec) {
-       diag "sleeping ${sec}s, imap://$host:$port/$mailbox available";
+       diag "sleeping ${sec}s, imap://$host_port/$mailbox available";
        diag "tmpdir=$tmpdir (Maildirs available)";
        diag "stdout=$out";
        diag "stderr=$err";
index b6ac3e21685e90142a8039fc90fa99c4b3cb6c5e..3a229883409e6847042ca82fd8c7dbcbbcc2206b 100644 (file)
@@ -152,11 +152,11 @@ $make_local_server = sub {
        # not using multiple workers, here, since we want to increase
        # the chance of tripping concurrency bugs within PublicInbox/IMAP*.pm
        my $cmd = [ '-imapd', "--stdout=$out", "--stderr=$err", '-W0' ];
-       push @$cmd, '-limap://'.$imap->sockhost.':'.$imap->sockport;
+       push @$cmd, '-limap://'.tcp_host_port($imap);
        if ($test_tls) {
                my $imaps = tcp_server();
                $rdr->{4} = $imaps;
-               push @$cmd, '-limaps://'.$imaps->sockhost.':'.$imaps->sockport;
+               push @$cmd, '-limaps://'.tcp_host_port($imaps);
                push @$cmd, "--cert=$cert", "--key=$key";
                my $tls_opt = [
                        SSL_hostname => 'server.local',
index e4b3b8cd050d1b30c1fd0e8982496b106f0209c0..99d8cb0dbe66a7f8c3005ca6fb9066aba84fe022 100644 (file)
@@ -45,7 +45,7 @@ my $imaps = tcp_server();
 EOF
        close $fh or die "close: $!\n";
 }
-my $imaps_addr = $imaps->sockhost . ':' . $imaps->sockport;
+my $imaps_addr = tcp_host_port($imaps);
 my $env = { PI_CONFIG => $pi_config };
 my $arg = $TEST_TLS ? [ "-limaps://$imaps_addr/?cert=$cert,key=$key" ] : [];
 my $cmd = [ '-imapd', '-W0', @$arg, "--stdout=$out", "--stderr=$err" ];
index efe97c027a43ba7c076698cbbd15d154f1ce3d93..83f024f984ebdf9f56d45c433fd919201ba9ead7 100644 (file)
@@ -169,8 +169,7 @@ sub make_local_server {
                open my $fh, '>', $_ or die "truncate: $!";
        }
        my $sock = tcp_server();
-       ok($sock, 'sock created');
-       $host_port = $sock->sockhost . ':' . $sock->sockport;
+       $host_port = tcp_host_port($sock);
 
        # not using multiple workers, here, since we want to increase
        # the chance of tripping concurrency bugs within PublicInbox/NNTP*.pm
index cd0d493899bd654a825c6fc78e2ae65f8318448e..85db036c78997063bc3ef7a538086c155e955612 100644 (file)
@@ -8,12 +8,15 @@ use PublicInbox::Inbox;
 use Net::NNTP;
 my $inboxdir = $ENV{GIANT_INBOX_DIR} // $ENV{GIANT_PI_DIR};
 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless defined($inboxdir);
-my ($host_port, $group, %opts, $s, $td, $tmp_obj);
+my ($host_port, $group, $s, $td, $tmp_obj);
 use PublicInbox::TestCommon;
 
 if (($ENV{NNTP_TEST_URL} || '') =~ m!\Anntp://([^/]+)/([^/]+)\z!) {
        ($host_port, $group) = ($1, $2);
        $host_port .= ":119" unless index($host_port, ':') > 0;
+       my $six = substr($host_port, 0, 1) eq '[' ? '6' : '';
+       my $cls = "IO::Socket::INET$six";
+       $cls->new(Proto => 'tcp', Timeout => 1, PeerAddr => $host_port);
 } else {
        $group = 'inbox.test.perf.nntpd';
        my $ibx = { inboxdir => $inboxdir, newsgroup => $group };
@@ -34,18 +37,11 @@ if (($ENV{NNTP_TEST_URL} || '') =~ m!\Anntp://([^/]+)/([^/]+)\z!) {
        }
 
        my $sock = tcp_server();
-       ok($sock, 'sock created');
        my $cmd = [ '-nntpd', '-W0' ];
        $td = start_script($cmd, { PI_CONFIG => $pi_config }, { 3 => $sock });
-       $host_port = $sock->sockhost . ':' . $sock->sockport;
+       $host_port = tcp_host_port($sock);
+       $s = tcp_connect($sock);
 }
-%opts = (
-       PeerAddr => $host_port,
-       Proto => 'tcp',
-       Timeout => 1,
-);
-$s = IO::Socket::INET->new(%opts);
-$s->autoflush(1);
 my $buf = $s->getline;
 like($buf, qr/\A201 .* ready - post via email\r\n/s, 'got greeting');
 
index 2f2fcc4463ce2fec5fc2f1f67ffb519a94b0ebdf..880458fb96689aad3a5263a7d030102c0a821af4 100644 (file)
@@ -67,8 +67,7 @@ SKIP: {
        my ($out, $err) = map { "$tmpdir/std$_.log" } qw(out err);
        my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
        my $td = start_script($cmd, undef, { 3 => $sock });
-       my ($h, $p) = ($sock->sockhost, $sock->sockport);
-
+       my ($h, $p) = tcp_host_port($sock);
        local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
        while (($ibx_name, $urls) = each %$todo) {
                Plack::Test::ExternalServer::test_psgi(client => $client);