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 9F5731F5C4 for ; Fri, 15 Nov 2019 09:51:05 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 26/29] t/v2mda: switch to run_script in many places Date: Fri, 15 Nov 2019 09:50:57 +0000 Message-Id: <20191115095100.25633-27-e@80x24.org> In-Reply-To: <20191115095100.25633-1-e@80x24.org> References: <20191115095100.25633-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This more than doubles the speed of the test. --- t/v2mda.t | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/t/v2mda.t b/t/v2mda.t index ebcbd1f4..0cd852b1 100644 --- a/t/v2mda.t +++ b/t/v2mda.t @@ -34,8 +34,6 @@ my $mime = PublicInbox::MIME->create( body => "hello world\n", ); -my $mda = "blib/script/public-inbox-mda"; -ok(-f "blib/script/public-inbox-mda", '-mda exists'); my $main_bin = getcwd()."/t/main-bin"; my $fail_bin = getcwd()."/t/fail-bin"; local $ENV{PI_DIR} = "$tmpdir/foo"; @@ -44,26 +42,19 @@ local $ENV{PATH} = "$main_bin:blib/script:$ENV{PATH}"; my $faildir = "$tmpdir/fail"; local $ENV{PI_EMERGENCY} = $faildir; ok(mkdir $faildir); -my @cmd = (qw(public-inbox-init), "-V$V", $ibx->{name}, +my @cmd = (qw(-init), "-V$V", $ibx->{name}, $ibx->{inboxdir}, 'http://localhost/test', $ibx->{address}->[0]); -ok(PublicInbox::Import::run_die(\@cmd), 'initialized v2 inbox'); +ok(run_script(\@cmd), 'initialized v2 inbox'); -open my $tmp, '+>', undef or die "failed to open anonymous tempfile: $!"; -ok($tmp->print($mime->as_string), 'wrote to temporary file'); -ok($tmp->flush, 'flushed temporary file'); -ok($tmp->sysseek(0, SEEK_SET), 'seeked'); - -my $rdr = { 0 => fileno($tmp) }; +my $rdr = { 0 => \($mime->as_string) }; local $ENV{ORIGINAL_RECIPIENT} = 'test@example.com'; -ok(PublicInbox::Import::run_die(['public-inbox-mda'], undef, $rdr), - 'mda delivered a message'); +ok(run_script(['-mda'], undef, $rdr), 'mda delivered a message'); $ibx = PublicInbox::Inbox->new($ibx); if ($V == 1) { - my $cmd = [ 'public-inbox-index', "$tmpdir/inbox" ]; - ok(PublicInbox::Import::run_die($cmd, undef, $rdr), 'v1 indexed'); + ok(run_script([ '-index', "$tmpdir/inbox" ]), 'v1 indexed'); } my $msgs = $ibx->search->query(''); is(scalar(@$msgs), 1, 'only got one message'); @@ -75,15 +66,8 @@ is($saved->{mime}->as_string, $mime->as_string, 'injected message'); is_deeply(\@new, [], 'nothing in faildir'); local $ENV{PATH} = $fail_path; $mime->header_set('Message-ID', ''); - ok($tmp->sysseek(0, SEEK_SET) && - $tmp->truncate(0) && - $tmp->print($mime->as_string) && - $tmp->flush && - $tmp->sysseek(0, SEEK_SET), - 'rewound and rewrite temporary file'); - my $cmd = ['public-inbox-mda']; - ok(PublicInbox::Import::run_die($cmd, undef, $rdr), - 'mda did not die on "spam"'); + $rdr->{0} = \($mime->as_string); + ok(run_script(['-mda'], undef, $rdr), 'mda did not die on "spam"'); @new = glob("$faildir/new/*"); is(scalar(@new), 1, 'got a message in faildir'); $msgs = $ibx->search->reopen->query(''); @@ -94,9 +78,8 @@ is($saved->{mime}->as_string, $mime->as_string, 'injected message'); my $k = 'publicinboxmda.spamcheck'; is(system('git', 'config', "--file=$config", $k, 'none'), 0, 'disabled spamcheck for mda'); - ok($tmp->sysseek(0, SEEK_SET), 'rewound input file'); - ok(PublicInbox::Import::run_die($cmd, undef, $rdr), 'mda did not die'); + ok(run_script(['-mda'], undef, $rdr), 'mda did not die'); my @again = glob("$faildir/new/*"); is_deeply(\@again, \@new, 'no new message in faildir'); $msgs = $ibx->search->reopen->query(''); @@ -106,9 +89,8 @@ is($saved->{mime}->as_string, $mime->as_string, 'injected message'); { my $patch = 't/data/0001.patch'; open my $fh, '<', $patch or die "failed to open $patch: $!\n"; - $rdr = { 0 => fileno($fh) }; - ok(PublicInbox::Import::run_die(['public-inbox-mda'], undef, $rdr), - 'mda delivered a patch'); + $rdr->{0} = \(do { local $/; <$fh> }); + ok(run_script(['-mda'], undef, $rdr), 'mda delivered a patch'); my $post = $ibx->search->reopen->query('dfpost:6e006fd7'); is(scalar(@$post), 1, 'got one result for dfpost'); my $pre = $ibx->search->query('dfpre:090d998');