unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] t/lei-refresh-mail-sync: improve test reliability
@ 2021-09-18 22:38 Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2021-09-18 22:38 UTC (permalink / raw)
  To: meta

We can't assume -imapd will be ready by the time we try to
connect to it after restart when using "-l $ADDR".  So recreate
the (closed-for-testing) listen socket in the parent and hand it
off to -imapd as we do normally
---
 t/lei-refresh-mail-sync.t | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/t/lei-refresh-mail-sync.t b/t/lei-refresh-mail-sync.t
index 90356b57..43fbc50a 100644
--- a/t/lei-refresh-mail-sync.t
+++ b/t/lei-refresh-mail-sync.t
@@ -4,6 +4,7 @@
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 require_mods(qw(lei));
 use File::Path qw(remove_tree);
+require Socket;
 
 my $stop_daemon = sub { # needed since we don't have inotify
 	lei_ok qw(daemon-pid);
@@ -81,8 +82,10 @@ SKIP: {
 	my $cfg_path2 = "$home/cfg2";
 	File::Copy::cp($cfg_path, $cfg_path2);
 	my $env = { PI_CONFIG => $cfg_path2 };
+	my $sock_cls;
 	for my $x (qw(imapd)) {
 		my $s = tcp_server;
+		$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");
@@ -124,10 +127,17 @@ SKIP: {
 	ok(!(lei 'refresh-mail-sync', '--all'), '--all fails on dead -imapd');
 
 	# 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};
-	push @$cmd, '-l', $srv->{imapd}->{addr};
-	$srv->{imapd}->{td} = start_script($cmd, $env) or xbail "@$cmd";
-
+	$srv->{imapd}->{td} = start_script($cmd, $env, { 3 => $listen }) or
+		xbail "@$cmd";
 	lei_ok 'refresh-mail-sync', '--all';
 	lei_ok 'inspect', "blob:$oid";
 	is($lei_out, $before, 'no changes when server was down');

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] t/lei-refresh-mail-sync: improve test reliability
@ 2023-03-28 10:53 Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2023-03-28 10:53 UTC (permalink / raw)
  To: meta

Lack of signalfd/EVFILT_SIGNAL means we need to kill a
process repeatedly to ensure it wakes up.
---
 t/lei-refresh-mail-sync.t | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/t/lei-refresh-mail-sync.t b/t/lei-refresh-mail-sync.t
index 0498a0c4..8ccc68c6 100644
--- a/t/lei-refresh-mail-sync.t
+++ b/t/lei-refresh-mail-sync.t
@@ -137,8 +137,12 @@ SKIP: {
 	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');
+	{
+		local $SIG{CHLD} = sub { $ar->join('TERM'); undef $ar };
+		do {
+			eval { $ar->kill and tick(0.01) }
+		} while (defined($ar));
+	}
 
 	my $cmd = $srv->{imapd}->{cmd};
 	my $s = $srv->{imapd}->{s};

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-28 10:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-28 10:53 [PATCH] t/lei-refresh-mail-sync: improve test reliability Eric Wong
  -- strict thread matches above, loose matches on Subject: below --
2021-09-18 22:38 Eric Wong

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