]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/v2mirror.t
t/httpd-corner: wait for worker process death
[public-inbox.git] / t / v2mirror.t
index f826775cd5d52b013748850c4bdcedf2f7165c13..2c7f6a8418f23e07858e079a872f8193f0cd66ac 100644 (file)
@@ -8,8 +8,7 @@ require_git(2.6);
 
 # Integration tests for HTTP cloning + mirroring
 foreach my $mod (qw(Plack::Util Plack::Builder
-                       HTTP::Date HTTP::Status Search::Xapian DBD::SQLite
-                       IPC::Run)) {
+                       HTTP::Date HTTP::Status Search::Xapian DBD::SQLite)) {
        eval "require $mod";
        plan skip_all => "$mod missing for v2mirror.t" if $@;
 }
@@ -59,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();
@@ -84,10 +87,11 @@ foreach my $i (0..$epoch_max) {
        ok(-d "$tmpdir/m/git/$i.git", "mirror $i OK");
 }
 
-@cmd = ("$script-init", '-V2', 'm', "$tmpdir/m", 'http://example.com/m',
+@cmd = ("-init", '-V2', 'm', "$tmpdir/m", 'http://example.com/m',
        'alt@example.com');
-is(system(@cmd), 0, 'initialized public-inbox -V2');
-is(system("$script-index", "$tmpdir/m"), 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);
@@ -99,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) {
@@ -113,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');
-is(system("$script-index", "$tmpdir/m"), 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');
@@ -131,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};
@@ -141,9 +146,13 @@ is(scalar($mset->items), 0, 'purged message gone from origin');
 
 fetch_each_epoch();
 {
-       my $cmd = [ "$script-index", '--prune', "$tmpdir/m" ];
-       my ($in, $out, $err) = ('', '', '');
-       ok(IPC::Run::run($cmd, \$in, \$out, \$err), '-index --prune');
+       $ibx->cleanup;
+       PublicInbox::InboxWritable::cleanup($mibx);
+       $v2w->done;
+       my $cmd = [ '-index', '--prune', "$tmpdir/m" ];
+       my ($out, $err) = ('', '');
+       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,14 @@ 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 ($in, $out, $err) = ('', '', '');
-       my $cmd = [ "$script-index", "$tmpdir/m" ];
-       ok(IPC::Run::run($cmd, \$in, \$out, \$err), 'index ran');
+       my $cmd = [ "-index", "$tmpdir/m" ];
+       my ($out, $err) = ('', '');
+       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});
        is(scalar($mset->items), 0, '1@example.com no longer visible in mirror');