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-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 C3A761FD71 for ; Mon, 15 Mar 2021 11:58:30 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 19/35] t/psgi_scan_all: create_inbox lots saved Date: Mon, 15 Mar 2021 12:58:10 +0100 Message-Id: <20210315115826.17591-20-e@80x24.org> In-Reply-To: <20210315115826.17591-1-e@80x24.org> References: <20210315115826.17591-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: A fair mount of setup code goes away and saves us a few hundred milliseconds. --- t/psgi_scan_all.t | 48 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/t/psgi_scan_all.t b/t/psgi_scan_all.t index 80b855e1..09e8eaf9 100644 --- a/t/psgi_scan_all.t +++ b/t/psgi_scan_all.t @@ -1,53 +1,38 @@ +#!perl -w # Copyright (C) 2019-2021 all contributors # License: AGPL-3.0+ use strict; -use warnings; -use Test::More; +use v5.10.1; +use PublicInbox::TestCommon; use PublicInbox::Eml; use PublicInbox::Config; -use PublicInbox::TestCommon; my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape DBD::SQLite); require_git 2.6; require_mods(@mods); -use_ok 'PublicInbox::V2Writable'; +use_ok 'PublicInbox::WWW'; foreach my $mod (@mods) { use_ok $mod; } -my ($tmp, $for_destroy) = tmpdir(); my $cfg = ''; - foreach my $i (1..2) { - my $cfgpfx = "publicinbox.test-$i"; - my $addr = "test-$i\@example.com"; - my $inboxdir = "$tmp/$i"; - $cfg .= "$cfgpfx.address=$addr\n"; - $cfg .= "$cfgpfx.inboxdir=$inboxdir\n"; - $cfg .= "$cfgpfx.url=http://example.com/$i\n"; - my $opt = { - inboxdir => $inboxdir, - name => "test-$i", - version => 2, - indexlevel => 'basic', - -primary_address => $addr, - }; - my $ibx = PublicInbox::Inbox->new($opt); - my $im = PublicInbox::V2Writable->new($ibx, 1); - $im->{parallel} = 0; - $im->init_inbox(0); - my $mime = PublicInbox::Eml->new(< 2, indexlevel => 'basic', + sub { + my ($im, $ibx) = @_; + $im->add(PublicInbox::Eml->new(<{-primary_address} Subject: s$i Message-ID: Date: Fri, 02 Oct 1993 00:00:00 +0000 hello world EOF + }; + my $cfgpfx = "publicinbox.test-$i"; + $cfg .= "$cfgpfx.address=$ibx->{-primary_address}\n"; + $cfg .= "$cfgpfx.inboxdir=$ibx->{inboxdir}\n"; + $cfg .= "$cfgpfx.url=http://example.com/$i\n"; - ok($im->add($mime), "added message to $i"); - $im->done; } -my $config = PublicInbox::Config->new(\$cfg); -use_ok 'PublicInbox::WWW'; -my $www = PublicInbox::WWW->new($config); +my $www = PublicInbox::WWW->new(PublicInbox::Config->new(\$cfg)); test_psgi(sub { $www->call(@_) }, sub { my ($cb) = @_; @@ -65,5 +50,4 @@ test_psgi(sub { $www->call(@_) }, sub { is($res->code, 404, "404 on $x"); } }); - -done_testing(); +done_testing;