about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-11-15 09:50:51 +0000
committerEric Wong <e@80x24.org>2019-11-16 11:05:23 +0000
commit1d409006c6932c2be45dafd826242654cda23c6c (patch)
tree48b2f6d36746177ff9905e023c39c12cb120c3e6
parent53a35a1c53a5a01e5cadc2a70a437d390f7edd4b (diff)
downloadpublic-inbox-1d409006c6932c2be45dafd826242654cda23c6c.tar.gz
We need to be careful and explicitly close FDs before doing
-index, since we can't rely on FD_CLOEXEC without execve(2)
syscalls.
-rw-r--r--t/v2mirror.t27
1 files changed, 19 insertions, 8 deletions
diff --git a/t/v2mirror.t b/t/v2mirror.t
index 3c238093..2c7f6a84 100644
--- a/t/v2mirror.t
+++ b/t/v2mirror.t
@@ -58,9 +58,13 @@ for my $i (1..9) {
 my $epoch_max = $v2w->{epoch_max};
 ok($epoch_max > 0, "multiple epochs");
 $v2w->done;
+$ibx->cleanup;
 
 my ($sock, $pid);
-END { kill 'TERM', $pid if defined $pid };
+
+# TODO: replace this with ->DESTROY:
+my $owner_pid = $$;
+END { kill('TERM', $pid) if defined($pid) && $owner_pid == $$ };
 
 $! = 0;
 $sock = tcp_server();
@@ -85,8 +89,9 @@ foreach my $i (0..$epoch_max) {
 
 @cmd = ("-init", '-V2', 'm', "$tmpdir/m", 'http://example.com/m',
         'alt@example.com');
-ok(run_script(\@cmd, undef, {run_mode => 0}), 'initialized public-inbox -V2');
-ok(run_script(['-index', "$tmpdir/m"], undef, { run_mode => 0}), 'indexed');
+ok(run_script(\@cmd), 'initialized public-inbox -V2');
+
+ok(run_script(['-index', "$tmpdir/m"]), 'indexed');
 
 my $mibx = { inboxdir => "$tmpdir/m", address => 'alt@example.com' };
 $mibx = PublicInbox::Inbox->new($mibx);
@@ -98,7 +103,8 @@ for my $i (10..15) {
         $mime->header_set('Subject', "subject = $i");
         ok($v2w->add($mime), "add msg $i OK");
 }
-$v2w->barrier;
+$v2w->done;
+$ibx->cleanup;
 
 sub fetch_each_epoch {
         foreach my $i (0..$epoch_max) {
@@ -112,7 +118,7 @@ fetch_each_epoch();
 
 my $mset = $mibx->search->reopen->query('m:15@example.com', {mset => 1});
 is(scalar($mset->items), 0, 'new message not found in mirror, yet');
-ok(run_script(["-index", "$tmpdir/m"], undef, {run_mode=>0}), 'index updated');
+ok(run_script(["-index", "$tmpdir/m"]), 'index updated');
 is_deeply([$mibx->mm->minmax], [$ibx->mm->minmax], 'index synched minmax');
 $mset = $mibx->search->reopen->query('m:15@example.com', {mset => 1});
 is(scalar($mset->items), 1, 'found message in mirror');
@@ -130,7 +136,7 @@ $mime->header_set('Subject', 'subject = 10');
         is_deeply(\@subj, ["# subject = 10"], "only rewrote one");
 }
 
-$v2w->barrier;
+$v2w->done;
 
 my $msgs = $mibx->search->{over_ro}->get_thread('10@example.com');
 my $to_purge = $msgs->[0]->{blob};
@@ -140,9 +146,12 @@ is(scalar($mset->items), 0, 'purged message gone from origin');
 
 fetch_each_epoch();
 {
+        $ibx->cleanup;
+        PublicInbox::InboxWritable::cleanup($mibx);
+        $v2w->done;
         my $cmd = [ '-index', '--prune', "$tmpdir/m" ];
         my ($out, $err) = ('', '');
-        my $opt = { 1 => \$out, 2 => \$err, run_mode => 0 };
+        my $opt = { 1 => \$out, 2 => \$err };
         ok(run_script($cmd, undef, $opt), '-index --prune');
         like($err, qr/discontiguous range/, 'warned about discontiguous range');
         unlike($err, qr/fatal/, 'no scary fatal error shown');
@@ -172,11 +181,13 @@ is($mibx->git->check($to_purge), undef, 'unindex+prune successful in mirror');
         $mime->header_set('Subject', 'subject = 1');
         ok($v2w->remove($mime), 'removed <1@example.com> from source');
         $v2w->done;
+        $ibx->cleanup;
         fetch_each_epoch();
+        PublicInbox::InboxWritable::cleanup($mibx);
 
         my $cmd = [ "-index", "$tmpdir/m" ];
         my ($out, $err) = ('', '');
-        my $opt = { 1 => \$out, 2 => \$err, run_mode => 0 };
+        my $opt = { 1 => \$out, 2 => \$err };
         ok(run_script($cmd, undef, $opt), 'index ran');
         is($err, '', 'no errors reported by index');
         $mset = $mibx->search->reopen->query('m:1@example.com', {mset => 1});