user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] t/lei-refresh-mail-sync: speed up test on FreeBSD 12
Date: Tue,  2 Nov 2021 09:24:39 +0000	[thread overview]
Message-ID: <20211102092439.12590-1-e@80x24.org> (raw)

And improve reliability while we're at it.  It seems closing a
TCP listen socket on FreeBSD 12.2 doesn't cause connect()-ing
clients to fail.  This happens regardless of whether a socket is
IPv4 or IPv6

This non-failure was causing tests to timeout slowly on the
client side instead of failing immediately.  We now fork a new
process which does nothing but accept() + shutdown() to emulate
a dead server.

Reliability improves on all OSes since there's never a point in
time when another process can bind the socket.
---
 t/lei-refresh-mail-sync.t | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/t/lei-refresh-mail-sync.t b/t/lei-refresh-mail-sync.t
index 43fbc50a..ea83a513 100644
--- a/t/lei-refresh-mail-sync.t
+++ b/t/lei-refresh-mail-sync.t
@@ -88,12 +88,9 @@ SKIP: {
 		$sock_cls //= ref($s);
 		my $cmd = [ "-$x", '-W0', "--stdout=$home/$x.out",
 			"--stderr=$home/$x.err" ];
-		my $td = start_script($cmd, $env, { 3 => $s}) or xbail("-$x");
-		$srv->{$x} = {
-			addr => (my $scalar = tcp_host_port($s)),
-			td => $td,
-			cmd => $cmd,
-		};
+		my $td = start_script($cmd, $env, { 3 => $s }) or xbail("-$x");
+		my $addr = tcp_host_port($s);
+		$srv->{$x} = { addr => $addr, td => $td, cmd => $cmd, s => $s };
 	}
 	my $url = "imap://$srv->{imapd}->{addr}/t.v1.0";
 	lei_ok 'import', $url, '+L:v1';
@@ -123,20 +120,26 @@ SKIP: {
 	$before = $lei_out;
 	delete $srv->{imapd}->{td}; # kill + join daemon
 
+	my $pid = fork // xbail "fork";
+	if ($pid == 0) { # dummy server to kill new connections
+		$SIG{TERM} = sub { POSIX::_exit(0) };
+		$srv->{imapd}->{s}->blocking(1);
+		while (1) {
+			my $caddr = accept(my $c, $srv->{imapd}->{s}) // next;
+			shutdown($c, 2);
+		}
+		POSIX::_exit(0);
+	}
+	my $ar = PublicInbox::AutoReap->new($pid);
 	ok(!(lei 'refresh-mail-sync', $url), 'URL fails on dead -imapd');
 	ok(!(lei 'refresh-mail-sync', '--all'), '--all fails on dead -imapd');
+	$ar->kill for qw(avoid sig wake miss-no signalfd or EVFILT_SIG);
+	$ar->join('TERM');
 
-	# restart server (somewhat dangerous since we released the socket)
-	my $listen = $sock_cls->new(
-		ReuseAddr => 1,
-		Proto => 'tcp',
-		Type => Socket::SOCK_STREAM(),
-		Listen => 1024,
-		Blocking => 0,
-		LocalAddr => $srv->{imapd}->{addr},
-	) or xbail "$sock_cls->new: $!";
 	my $cmd = $srv->{imapd}->{cmd};
-	$srv->{imapd}->{td} = start_script($cmd, $env, { 3 => $listen }) or
+	my $s = $srv->{imapd}->{s};
+	$s->blocking(0);
+	$srv->{imapd}->{td} = start_script($cmd, $env, { 3 => $s }) or
 		xbail "@$cmd";
 	lei_ok 'refresh-mail-sync', '--all';
 	lei_ok 'inspect', "blob:$oid";

                 reply	other threads:[~2021-11-02  9:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20211102092439.12590-1-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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).