From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 95B901F953 for ; Tue, 2 Nov 2021 09:24:39 +0000 (UTC) From: Eric Wong 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 Message-Id: <20211102092439.12590-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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";