unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 05/13] tests: favor IPv6
Date: Sun,  7 Feb 2021 23:05:13 -1000	[thread overview]
Message-ID: <20210208090521.28909-6-e@80x24.org> (raw)
In-Reply-To: <20210208090521.28909-1-e@80x24.org>

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
---
 lib/PublicInbox/TestCommon.pm | 30 ++++++++++++++++++++++++------
 t/extsearch.t                 |  2 +-
 t/httpd-corner.psgi           |  2 +-
 t/httpd-corner.t              | 12 +++++-------
 t/httpd-https.t               |  2 +-
 t/httpd-unix.t                |  7 +++----
 t/httpd.t                     |  8 +++-----
 t/imapd-tls.t                 |  4 ++--
 t/imapd.t                     |  8 ++------
 t/lei-mirror.t                |  2 +-
 t/nntpd-tls.t                 |  4 ++--
 t/nntpd.t                     | 11 ++++-------
 t/psgi_attach.t               |  2 +-
 t/psgi_v2.t                   |  2 +-
 t/solver_git.t                |  2 +-
 t/v2mirror.t                  |  3 +--
 t/v2writable.t                |  3 +--
 t/www_altid.t                 |  2 +-
 t/www_listing.t               |  3 +--
 xt/git-http-backend.t         |  4 +---
 xt/httpd-async-stream.t       |  2 +-
 xt/imapd-mbsync-oimap.t       |  4 +++-
 xt/imapd-validate.t           |  4 ++--
 xt/mem-imapd-tls.t            |  2 +-
 xt/nntpd-validate.t           |  3 +--
 xt/perf-nntpd.t               | 16 ++++++----------
 xt/solver.t                   |  3 +--
 27 files changed, 72 insertions(+), 75 deletions(-)

diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 5cce44e4..2f4ca622 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -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,
diff --git a/t/extsearch.t b/t/extsearch.t
index 26c3d4ae..d199fc7b 100644
--- a/t/extsearch.t
+++ b/t/extsearch.t
@@ -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 $!;
diff --git a/t/httpd-corner.psgi b/t/httpd-corner.psgi
index 5436a74d..5fab2ba4 100644
--- a/t/httpd-corner.psgi
+++ b/t/httpd-corner.psgi
@@ -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) = @_;
diff --git a/t/httpd-corner.t b/t/httpd-corner.t
index c3f80530..794d8aeb 100644
--- a/t/httpd-corner.t
+++ b/t/httpd-corner.t
@@ -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: $!";
diff --git a/t/httpd-https.t b/t/httpd-https.t
index a2166ce6..b37492eb 100644
--- a/t/httpd-https.t
+++ b/t/httpd-https.t
@@ -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" ],
diff --git a/t/httpd-unix.t b/t/httpd-unix.t
index 2d3cecc1..fe4a2161 100644
--- a/t/httpd-unix.t
+++ b/t/httpd-unix.t
@@ -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');
 }
 
diff --git a/t/httpd.t b/t/httpd.t
index 2fc28355..af9fbfeb 100644
--- 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');
diff --git a/t/imapd-tls.t b/t/imapd-tls.t
index e40ae1e8..ab90ddec 100644
--- a/t/imapd-tls.t
+++ b/t/imapd-tls.t
@@ -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;
 
diff --git a/t/imapd.t b/t/imapd.t
index 1df9d26e..0583dfdd 100644
--- 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",
diff --git a/t/lei-mirror.t b/t/lei-mirror.t
index 667284fd..e3707979 100644
--- a/t/lei-mirror.t
+++ b/t/lei-mirror.t
@@ -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 });
diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t
index 1194be6f..8dab4ca8 100644
--- a/t/nntpd-tls.t
+++ b/t/nntpd-tls.t
@@ -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;
 
diff --git a/t/nntpd.t b/t/nntpd.t
index 63287d43..6c100138 100644
--- 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",
diff --git a/t/psgi_attach.t b/t/psgi_attach.t
index 65d704bf..f53b7510 100644
--- a/t/psgi_attach.t
+++ b/t/psgi_attach.t
@@ -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);
 }
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 7ab60adc..81355f04 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -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');
diff --git a/t/solver_git.t b/t/solver_git.t
index d03a6f38..3ae7259a 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -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);
 	}
diff --git a/t/v2mirror.t b/t/v2mirror.t
index ebad2566..12e3fcd0 100644
--- a/t/v2mirror.t
+++ b/t/v2mirror.t
@@ -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;
diff --git a/t/v2writable.t b/t/v2writable.t
index f5c8313a..f0fa8a79 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -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-');
diff --git a/t/www_altid.t b/t/www_altid.t
index 14eda030..784acc8b 100644
--- a/t/www_altid.t
+++ b/t/www_altid.t
@@ -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);
 }
diff --git a/t/www_listing.t b/t/www_listing.t
index 1bcbaefb..63ef2eac 100644
--- a/t/www_listing.t
+++ b/t/www_listing.t
@@ -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');
 
diff --git a/xt/git-http-backend.t b/xt/git-http-backend.t
index dcff72cc..adadebb0 100644
--- a/xt/git-http-backend.t
+++ b/xt/git-http-backend.t
@@ -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 });
 }
diff --git a/xt/httpd-async-stream.t b/xt/httpd-async-stream.t
index f6715c58..c7039f3e 100644
--- a/xt/httpd-async-stream.t
+++ b/xt/httpd-async-stream.t
@@ -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";
diff --git a/xt/imapd-mbsync-oimap.t b/xt/imapd-mbsync-oimap.t
index 5f671fc8..6635e2b4 100644
--- a/xt/imapd-mbsync-oimap.t
+++ b/xt/imapd-mbsync-oimap.t
@@ -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";
diff --git a/xt/imapd-validate.t b/xt/imapd-validate.t
index b6ac3e21..3a229883 100644
--- a/xt/imapd-validate.t
+++ b/xt/imapd-validate.t
@@ -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',
diff --git a/xt/mem-imapd-tls.t b/xt/mem-imapd-tls.t
index e4b3b8cd..99d8cb0d 100644
--- a/xt/mem-imapd-tls.t
+++ b/xt/mem-imapd-tls.t
@@ -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" ];
diff --git a/xt/nntpd-validate.t b/xt/nntpd-validate.t
index efe97c02..83f024f9 100644
--- a/xt/nntpd-validate.t
+++ b/xt/nntpd-validate.t
@@ -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
diff --git a/xt/perf-nntpd.t b/xt/perf-nntpd.t
index cd0d4938..85db036c 100644
--- a/xt/perf-nntpd.t
+++ b/xt/perf-nntpd.t
@@ -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');
 
diff --git a/xt/solver.t b/xt/solver.t
index 2f2fcc44..880458fb 100644
--- a/xt/solver.t
+++ b/xt/solver.t
@@ -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);

  parent reply	other threads:[~2021-02-08  9:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-08  9:05 [PATCH 00/13] lei approxidate, startup fix, --alert Eric Wong
2021-02-08  9:05 ` [PATCHv2 01/13] lei q: improve remote mboxrd UX + MUA Eric Wong
2021-02-08  9:05 ` [PATCH 02/13] lei_xsearch: quiet Eml warnings from remote mboxrds Eric Wong
2021-02-08  9:05 ` [PATCH 03/13] lei q: SIGWINCH process group with the terminal Eric Wong
2021-02-08  9:05 ` [PATCH 04/13] lei q: support --alert=CMD for early MUA users Eric Wong
2021-02-08  9:05 ` Eric Wong [this message]
2021-02-08  9:05 ` [PATCH 06/13] ds: improve add_timer usability Eric Wong
2021-02-08  9:05 ` [PATCH 07/13] lei: start_pager: drop COLUMNS default Eric Wong
2021-02-08  9:05 ` [PATCH 08/13] lei: avoid racing on unlink + bind + listen Eric Wong
2021-02-08  9:05 ` [PATCH 09/13] lei: drop BSD::Resource usage Eric Wong
2021-02-08  9:05 ` [PATCH 10/13] git: implement date_parse method Eric Wong
2021-02-08  9:05 ` [PATCH 11/13] lei q: use git approxidate with d:, dt: and rt: ranges Eric Wong
2021-02-10  9:59   ` [PATCH] search: fix argv handling of quoted phrases Eric Wong
2021-02-08  9:05 ` [PATCH 12/13] search: use one git-rev-parse process for all dates Eric Wong
2021-02-08  9:05 ` [PATCH 13/13] spawnpp: raise exception on E2BIG errors Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210208090521.28909-6-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).