unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 00/35] memoize inbox creations
@ 2021-03-15 11:57 Eric Wong
  2021-03-15 11:57 ` [PATCH 01/35] test_common: add create_inbox helper sub Eric Wong
                   ` (34 more replies)
  0 siblings, 35 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:57 UTC (permalink / raw)
  To: meta

This speeds up a bunch of tests by a few dozen to hundreds of
milliseconds.  Part of it is due to disabling fsync/fdatasync in
a few more places.

Users with slower TMPDIR will notice more, and users with TMPDIR
pointed to tmpfs will notice it least.

Overall it's not hugely significant, but the diffstat
and LoC reduction still makes it nice even if there were
no performance improvements.

Eric Wong (35):
  test_common: add create_inbox helper sub
  t/lei_xsearch: use create_inbox
  test_common: minor simplifications to setup_public_inboxes
  t/imapd-tls: switch to create_inbox
  t/www_altid: use create_inbox
  t/xcpdb-reshard: use create_inbox
  t/v2dupindex: create_inbox
  t/admin: switch to create_inbox
  t/html_index: remove now-worthless test
  t/plack: use create_inbox
  t/psgi_attach: convert to create_inbox
  t/httpd: convert to create_inbox
  t/convert-compact: create_inbox
  t/altid: use create_inbox
  t/psgi_mount: switch to create_inbox
  t/feed: switch to create_inbox
  t/psgi_bad_mids: use create_inbox
  t/psgi_multipart_not: use create_inbox
  t/psgi_scan_all: create_inbox lots saved
  t/psgi_v2: create_inbox
  t/imapd: create_inbox (minor)
  t/solver_git: use create_inbox
  t/cgi: create_inbox
  t/edit: switch to create_inbox
  t/inbox_idle: switch to create_inbox
  t/lei_xsearch: use create_inbox
  t/indexlevels-mirror: use create_inbox
  t/multi-mid: use create_inbox
  t/psgi_search: use create_inbox
  t/miscsearch: use create_inbox
  t/nntpd-tls: use create_inbox
  t/nntpd: use create_inbox
  t/thread-index-gap: create_inbox
  t/altid_v2: create_inbox
  t/*: disable fsync on tests were create_inbox isn't worth it

 MANIFEST                      |   2 +-
 Makefile.PL                   |   3 +-
 lib/PublicInbox/TestCommon.pm |  67 ++++++++++++++---
 t/admin.t                     |  38 ++++------
 t/altid.t                     |  26 ++-----
 t/altid_v2.t                  |  48 +++++-------
 t/cgi.t                       |  84 +++++++++------------
 t/convert-compact.t           |  48 +++++-------
 t/data-gen/.gitignore         |   2 +
 t/edit.t                      |  34 ++++-----
 t/extsearch.t                 |   2 +
 t/feed.t                      |  53 ++++----------
 t/html_index.t                |  56 --------------
 t/httpd.t                     |  36 +++------
 t/imapd-tls.t                 |  38 +++-------
 t/imapd.t                     |  66 ++++++++---------
 t/inbox_idle.t                |  31 ++++----
 t/indexlevels-mirror.t        |  24 +++---
 t/lei-q-remote-import.t       |  20 ++---
 t/lei_xsearch.t               |  56 +++++---------
 t/miscsearch.t                |  28 +++----
 t/multi-mid.t                 |  34 +++------
 t/nntpd-tls.t                 |  52 ++++---------
 t/nntpd.t                     | 102 ++++++++++++--------------
 t/plack.t                     |  69 +++++++----------
 t/psgi_attach.t               |  56 ++++++--------
 t/psgi_bad_mids.t             |  46 ++++--------
 t/psgi_mount.t                |  35 ++++-----
 t/psgi_multipart_not.t        |  35 +++------
 t/psgi_scan_all.t             |  48 ++++--------
 t/psgi_search.t               |  37 +++-------
 t/psgi_v2.t                   | 134 ++++++++++++++++------------------
 t/purge.t                     |   1 +
 t/replace.t                   |   1 +
 t/solver_git.t                |  88 +++++++++++-----------
 t/thread-index-gap.t          |  24 +++---
 t/v1reindex.t                 |   1 +
 t/v2-add-remove-add.t         |   1 +
 t/v2dupindex.t                |  76 +++++++++----------
 t/v2mirror.t                  |   1 +
 t/v2reindex.t                 |   1 +
 t/v2writable.t                |   1 +
 t/watch_filter_rubylang.t     |   2 +
 t/watch_maildir_v2.t          |   1 +
 t/www_altid.t                 |  47 +++++-------
 t/xcpdb-reshard.t             |  54 ++++++--------
 46 files changed, 692 insertions(+), 1017 deletions(-)
 create mode 100644 t/data-gen/.gitignore
 delete mode 100644 t/html_index.t

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

* [PATCH 01/35] test_common: add create_inbox helper sub
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
@ 2021-03-15 11:57 ` Eric Wong
  2021-03-15 11:57 ` [PATCH 02/35] t/lei_xsearch: use create_inbox Eric Wong
                   ` (33 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:57 UTC (permalink / raw)
  To: meta

This saves over 100ms in t/lei-q-remote-import.t so far when
TMPDIR is on an SSD.  If we can memoize inbox creation to save a
few dozen milliseconds every test, this could add up to
noticeable savings across our entire test suite.
---
 MANIFEST                      |  1 +
 Makefile.PL                   |  3 +-
 lib/PublicInbox/TestCommon.pm | 55 ++++++++++++++++++++++++++++++++---
 t/data-gen/.gitignore         |  2 ++
 t/lei-q-remote-import.t       | 20 ++++---------
 5 files changed, 61 insertions(+), 20 deletions(-)
 create mode 100644 t/data-gen/.gitignore

diff --git a/MANIFEST b/MANIFEST
index 941a1f90..4d2cfb10 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -311,6 +311,7 @@ t/config.t
 t/config_limiter.t
 t/content_hash.t
 t/convert-compact.t
+t/data-gen/.gitignore
 t/data/0001.patch
 t/data/message_embed.eml
 t/dir_idle.t
diff --git a/Makefile.PL b/Makefile.PL
index 21d3d6ea..8165e601 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -176,7 +176,8 @@ WriteMakefile(
 	},
 	MAN3PODS => \%man3,
 	clean => {
-		FILES => 't/home*/setup* t/home*/t* t/home*/.public-inbox'
+		FILES => 't/home*/setup* t/home*/t* t/home*/.public-inbox '.
+			't/data-gen/*'
 	},
 );
 
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index af1b2e4f..77306a6e 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -14,9 +14,8 @@ our @EXPORT;
 BEGIN {
 	@EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods
 		run_script start_script key2sub xsys xsys_e xqx eml_load tick
-		have_xapian_compact json_utf8 setup_public_inboxes
-		tcp_host_port test_lei lei lei_ok
-		$lei_out $lei_err $lei_opt);
+		have_xapian_compact json_utf8 setup_public_inboxes create_inbox
+		tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt);
 	require Test::More;
 	my @methods = grep(!/\W/, @Test::More::EXPORT);
 	eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
@@ -587,7 +586,55 @@ sub setup_public_inboxes () {
 	$seen or BAIL_OUT 'no imports';
 	open my $fh, '>', $stamp or BAIL_OUT "open $stamp: $!";
 	@ret;
-};
+}
+
+sub create_inbox ($$;@) {
+	my $ident = shift;
+	my $cb = pop;
+	my %opt = @_;
+	require PublicInbox::Lock;
+	require PublicInbox::InboxWritable;
+	my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
+	my $dir = "t/data-gen/$base.$ident";
+	unless (-d $dir) {
+		mkdir $dir; # may race
+		-d $dir or BAIL_OUT "$dir could not be created: $!";
+	}
+	my $lk = bless { lock_path => "$dir/creat.lock" }, 'PublicInbox::Lock';
+	$opt{inboxdir} = File::Spec->rel2abs($dir);
+	$opt{name} //= $ident;
+	$opt{-no_fsync} = 1;
+	my $no_gc = delete $opt{-no_gc};
+	my $tmpdir = delete $opt{tmpdir};
+	my $addr = $opt{address} // [];
+	$opt{-primary_address} //= $addr->[0] // "$ident\@example.com";
+	my $parallel = delete($opt{importer_parallel}) // 0;
+	my $creat_opt = { nproc => delete($opt{nproc}) // 1 };
+	my $ibx = PublicInbox::InboxWritable->new({ %opt }, $creat_opt);
+	my $scope = $lk->lock_for_scope;
+	if (!-f "$dir/creat.stamp") {
+		my $im = $ibx->importer($parallel);
+		$cb->($im, $ibx);
+		$im->done if $im;
+		unless ($no_gc) {
+			my @to_gc = $ibx->version == 1 ? ($ibx->{inboxdir}) :
+					glob("$ibx->{inboxdir}/git/*.git");
+			for my $dir (@to_gc) {
+				xsys_e([ qw(git gc -q) ], { GIT_DIR => $dir });
+			}
+		}
+		open my $s, '>', "$dir/creat.stamp" or
+			BAIL_OUT "error creating $dir/creat.stamp: $!";
+	}
+	if ($tmpdir) {
+		undef $ibx;
+		xsys([qw(/bin/cp -Rp), $dir, $tmpdir]) == 0 or
+			BAIL_OUT "cp $dir $tmpdir";
+		$opt{inboxdir} = $tmpdir;
+		$ibx = PublicInbox::InboxWritable->new(\%opt);
+	}
+	$ibx;
+}
 
 package PublicInboxTestProcess;
 use strict;
diff --git a/t/data-gen/.gitignore b/t/data-gen/.gitignore
new file mode 100644
index 00000000..11e8933b
--- /dev/null
+++ b/t/data-gen/.gitignore
@@ -0,0 +1,2 @@
+# read-only test data generated by create_inbox
+*
diff --git a/t/lei-q-remote-import.t b/t/lei-q-remote-import.t
index 8b82579c..2293489a 100644
--- a/t/lei-q-remote-import.t
+++ b/t/lei-q-remote-import.t
@@ -5,7 +5,6 @@ use strict; use v5.10.1; use PublicInbox::TestCommon;
 require_git 2.6;
 require_mods(qw(json DBD::SQLite Search::Xapian));
 use PublicInbox::MboxReader;
-use PublicInbox::InboxWritable;
 my ($ro_home, $cfg_path) = setup_public_inboxes;
 my $sock = tcp_server;
 my ($tmpdir, $for_destroy) = tmpdir;
@@ -61,20 +60,11 @@ test_lei({ tmpdir => $tmpdir }, sub {
 	lei_ok(@cmd, '--lock=dotlock,timeout=0.000001',
 		\'succeeds after lock removal');
 
-	# XXX memoize this external creation
-	my $inboxdir = "$ENV{HOME}/tmp_git";
-	my $ibx = PublicInbox::InboxWritable->new({
-		name => 'tmp',
-		-primary_address => 'lei@example.com',
-		inboxdir => $inboxdir,
-		indexlevel => 'medium',
-	}, { nproc => 1 });
-	my $im = $ibx->importer(0);
-	$im->add(eml_load('t/utf8.eml')) or BAIL_OUT '->add';
-	$im->done;
-
-	run_script(['-index', $inboxdir], undef) or BAIL_OUT '-init';
-	lei_ok(qw(add-external -q), $inboxdir);
+	my $ibx = create_inbox 'local-external', indexlevel => 'medium', sub {
+		my ($im) = @_;
+		$im->add(eml_load('t/utf8.eml')) or BAIL_OUT '->add';
+	};
+	lei_ok(qw(add-external -q), $ibx->{inboxdir});
 	lei_ok(qw(q -o), "mboxrd:$o", '--only', $url,
 		'm:testmessage@example.com');
 	ok(-s $o, 'got result from remote external');

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

* [PATCH 02/35] t/lei_xsearch: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
  2021-03-15 11:57 ` [PATCH 01/35] test_common: add create_inbox helper sub Eric Wong
@ 2021-03-15 11:57 ` Eric Wong
  2021-03-15 11:57 ` [PATCH 03/35] test_common: minor simplifications to setup_public_inboxes Eric Wong
                   ` (32 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:57 UTC (permalink / raw)
  To: meta

Less code and noticeably faster when TMPDIR is on an SSD
---
 t/lei_xsearch.t | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/t/lei_xsearch.t b/t/lei_xsearch.t
index 5bfbcfe6..a1ab3ec8 100644
--- a/t/lei_xsearch.t
+++ b/t/lei_xsearch.t
@@ -3,7 +3,6 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
-use Test::More;
 use List::Util qw(shuffle max);
 use PublicInbox::TestCommon;
 use PublicInbox::Eml;
@@ -16,17 +15,11 @@ my ($home, $for_destroy) = tmpdir();
 my @ibx;
 for my $V (1..2) {
 	for my $i (3..6) {
-		my $ibx = PublicInbox::InboxWritable->new({
-			inboxdir => "$home/v$V-$i",
-			name => "test-v$V-$i",
-			version => $V,
-			indexlevel => 'medium',
-			-primary_address => "v$V-$i\@example.com",
-		}, { nproc => int(rand(8)) + 1 });
-		push @ibx, $ibx;
-		my $im = $ibx->importer(0);
-		for my $j (0..9) {
-			my $eml = PublicInbox::Eml->new(<<EOF);
+		push @ibx, create_inbox("v$V-$i", indexlevel => 'full',
+					version => $V, sub {
+			my ($im, $ibx) = @_;
+			for my $j (0..9) {
+				my $eml = PublicInbox::Eml->new(<<EOM);
 From: x\@example.com
 To: $ibx->{-primary_address}
 Date: Fri, 02 Oct 1993 0$V:0$i:0$j +0000
@@ -34,14 +27,14 @@ Subject: v${V}i${i}j$j
 Message-ID: <v${V}i${i}j$j\@example>
 
 ${V}er ${i}on j$j
-EOF
-			$im->add($eml);
-		}
-		$im->done;
+EOM
+				$im->add($eml) or BAIL_OUT '->add';
+			}
+		}); # create_inbox
 	}
 }
-my $first = shift @ibx; is($first->{name}, 'test-v1-3', 'first plucked');
-my $last = pop @ibx; is($last->{name}, 'test-v2-6', 'last plucked');
+my $first = shift @ibx; is($first->{name}, 'v1-3', 'first plucked');
+my $last = pop @ibx; is($last->{name}, 'v2-6', 'last plucked');
 my $eidx = PublicInbox::ExtSearchIdx->new("$home/eidx");
 $eidx->attach_inbox($first);
 $eidx->attach_inbox($last);

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

* [PATCH 03/35] test_common: minor simplifications to setup_public_inboxes
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
  2021-03-15 11:57 ` [PATCH 01/35] test_common: add create_inbox helper sub Eric Wong
  2021-03-15 11:57 ` [PATCH 02/35] t/lei_xsearch: use create_inbox Eric Wong
@ 2021-03-15 11:57 ` Eric Wong
  2021-03-15 11:57 ` [PATCH 04/35] t/imapd-tls: switch to create_inbox Eric Wong
                   ` (31 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:57 UTC (permalink / raw)
  To: meta

This will results in a small reduction in on-disk footprint
by removing Xapian docdata and reduction in code by removing
an unnecessary -index invocation.
---
 lib/PublicInbox/TestCommon.pm | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 77306a6e..6ca69174 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -558,8 +558,8 @@ sub setup_public_inboxes () {
 
 	local $ENV{PI_CONFIG} = $pi_config;
 	for my $V (1, 2) {
-		run_script([qw(-init), "-V$V", "t$V",
-				'--newsgroup', "t.v$V",
+		run_script([qw(-init --skip-docdata), "-V$V",
+				'--newsgroup', "t.v$V", "t$V",
 				"$test_home/t$V", "http://example.com/t$V",
 				"t$V\@example.com" ]) or BAIL_OUT "init v$V";
 	}
@@ -569,6 +569,7 @@ sub setup_public_inboxes () {
 	my $seen = 0;
 	$cfg->each_inbox(sub {
 		my ($ibx) = @_;
+		$ibx->{-no_fsync} = 1;
 		my $im = PublicInbox::InboxWritable->new($ibx)->importer(0);
 		my $V = $ibx->version;
 		my @eml = (glob('t/*.eml'), 't/data/0001.patch');
@@ -578,10 +579,6 @@ sub setup_public_inboxes () {
 			$seen++;
 		}
 		$im->done;
-		if ($V == 1) {
-			run_script(['-index', $ibx->{inboxdir}]) or
-				BAIL_OUT 'index v1';
-		}
 	});
 	$seen or BAIL_OUT 'no imports';
 	open my $fh, '>', $stamp or BAIL_OUT "open $stamp: $!";

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

* [PATCH 04/35] t/imapd-tls: switch to create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (2 preceding siblings ...)
  2021-03-15 11:57 ` [PATCH 03/35] test_common: minor simplifications to setup_public_inboxes Eric Wong
@ 2021-03-15 11:57 ` Eric Wong
  2021-03-15 11:57 ` [PATCH 05/35] t/www_altid: use create_inbox Eric Wong
                   ` (30 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:57 UTC (permalink / raw)
  To: meta

This saves another few dozen milliseconds and LoC.
---
 t/imapd-tls.t | 38 ++++++++++----------------------------
 1 file changed, 10 insertions(+), 28 deletions(-)

diff --git a/t/imapd-tls.t b/t/imapd-tls.t
index ab90ddec..125846e2 100644
--- a/t/imapd-tls.t
+++ b/t/imapd-tls.t
@@ -25,50 +25,32 @@ unless (-r $key && -r $cert) {
 }
 use_ok 'PublicInbox::TLS';
 use_ok 'IO::Socket::SSL';
-use PublicInbox::InboxWritable;
-require PublicInbox::SearchIdx;
 my $version = 1; # v2 needs newer git
 require_git('2.6') if $version >= 2;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
-my $inboxdir = "$tmpdir";
-my $pi_config = "$tmpdir/pi_config";
+my $pi_config;
 my $group = 'test-imapd-tls';
 my $addr = $group . '@example.com';
 my $starttls = tcp_server();
 my $imaps = tcp_server();
-my $ibx = PublicInbox::Inbox->new({
-	inboxdir => $inboxdir,
-	name => 'imapd-tls',
-	version => $version,
-	-primary_address => $addr,
-	indexlevel => 'basic',
-});
-$ibx = PublicInbox::InboxWritable->new($ibx, {nproc=>1});
-$ibx->init_inbox(0);
-{
+my $ibx = create_inbox 'imapd-tls', version => $version,
+			-primary_address => $addr, indexlevel => 'basic', sub {
+	my ($im, $ibx) = @_;
+	$im->add(eml_load('t/data/0001.patch')) or BAIL_OUT '->add';
+	$pi_config = "$ibx->{inboxdir}/pi_config";
 	open my $fh, '>', $pi_config or BAIL_OUT "open: $!";
-	print $fh <<EOF
+	print $fh <<EOF or BAIL_OUT "print: $!";
 [publicinbox "imapd-tls"]
-	inboxdir = $inboxdir
+	inboxdir = $ibx->{inboxdir}
 	address = $addr
 	indexlevel = basic
 	newsgroup = $group
 EOF
-	;
 	close $fh or BAIL_OUT "close: $!\n";
-}
-
-{
-	my $im = $ibx->importer(0);
-	ok($im->add(eml_load('t/data/0001.patch')), 'message added');
-	$im->done;
-	if ($version == 1) {
-		my $s = PublicInbox::SearchIdx->new($ibx, 1);
-		$s->index_sync;
-	}
-}
+};
+$pi_config //= "$ibx->{inboxdir}/pi_config";
 
 my $imaps_addr = tcp_host_port($imaps);
 my $starttls_addr = tcp_host_port($starttls);

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

* [PATCH 05/35] t/www_altid: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (3 preceding siblings ...)
  2021-03-15 11:57 ` [PATCH 04/35] t/imapd-tls: switch to create_inbox Eric Wong
@ 2021-03-15 11:57 ` Eric Wong
  2021-03-15 11:57 ` [PATCH 06/35] t/xcpdb-reshard: " Eric Wong
                   ` (29 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:57 UTC (permalink / raw)
  To: meta

This barely saves any time due to sqlite3(1) fsync,
but does save some lines of code.
---
 t/www_altid.t | 47 +++++++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/t/www_altid.t b/t/www_altid.t
index 784acc8b..7c2b6b21 100644
--- a/t/www_altid.t
+++ b/t/www_altid.t
@@ -1,10 +1,9 @@
+#!perl -w
 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
-use PublicInbox::Inbox;
-use PublicInbox::InboxWritable;
 use PublicInbox::Config;
 use PublicInbox::Spawn qw(which spawn);
 which('sqlite3') or plan skip_all => 'sqlite3 binary missing';
@@ -14,43 +13,35 @@ use_ok($_) for qw(Plack::Test HTTP::Request::Common);
 require_ok 'PublicInbox::Msgmap';
 require_ok 'PublicInbox::AltId';
 require_ok 'PublicInbox::WWW';
-my ($inboxdir, $for_destroy) = tmpdir();
+my ($tmpdir, $for_destroy) = tmpdir();
 my $aid = 'xyz';
-my $spec = "serial:$aid:file=blah.sqlite3";
-if ('setup') {
-	my $opts = {
-		inboxdir => $inboxdir,
-		name => 'test',
-		-primary_address => 'test@example.com',
-	};
-	my $ibx = PublicInbox::Inbox->new($opts);
-	$ibx = PublicInbox::InboxWritable->new($ibx, 1);
-	my $im = $ibx->importer(0);
-	my $mime = PublicInbox::Eml->new(<<'EOF');
+my $cfgpath;
+my $ibx = create_inbox 'test', indexlevel => 'basic', sub {
+	my ($im, $ibx) = @_;
+	$im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
 From: a@example.com
 Message-Id: <a@example.com>
 
 EOF
-	$im->add($mime);
-	$im->done;
-	mkdir "$inboxdir/public-inbox" or die;
+	# $im->done;
+	my $spec = "serial:$aid:file=blah.sqlite3";
 	my $altid = PublicInbox::AltId->new($ibx, $spec, 1);
 	$altid->mm_alt->mid_set(1, 'a@example.com');
-}
-
-my $cfgpath = "$inboxdir/cfg";
-open my $fh, '>', $cfgpath or die;
-print $fh <<EOF or die;
+	$cfgpath = "$ibx->{inboxdir}/cfg";
+	open my $fh, '>', $cfgpath or BAIL_OUT "open $cfgpath: $!";
+	print $fh <<EOF or BAIL_OUT $!;
 [publicinbox "test"]
-	inboxdir = $inboxdir
-	address = test\@example.com
+	inboxdir = $ibx->{inboxdir}
+	address = $ibx->{-primary_address}
 	altid = $spec
 	url = http://example.com/test
 EOF
-close $fh or die;
+	close $fh or BAIL_OUT $!;
+};
+$cfgpath //= "$ibx->{inboxdir}/cfg";
 my $cfg = PublicInbox::Config->new($cfgpath);
 my $www = PublicInbox::WWW->new($cfg);
-my $cmpfile = "$inboxdir/cmp.sqlite3";
+my $cmpfile = "$tmpdir/cmp.sqlite3";
 my $client = sub {
 	my ($cb) = @_;
 	my $res = $cb->(POST("/test/$aid.sql.gz"));
@@ -73,7 +64,7 @@ SKIP: {
 	require_mods(qw(Plack::Test::ExternalServer), 4);
 	my $env = { PI_CONFIG => $cfgpath };
 	my $sock = tcp_server() or die;
-	my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err);
+	my ($out, $err) = map { "$tmpdir/std$_.log" } qw(out err);
 	my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
 	my $td = start_script($cmd, $env, { 3 => $sock });
 	my ($h, $p) = tcp_host_port($sock);

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

* [PATCH 06/35] t/xcpdb-reshard: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (4 preceding siblings ...)
  2021-03-15 11:57 ` [PATCH 05/35] t/www_altid: use create_inbox Eric Wong
@ 2021-03-15 11:57 ` Eric Wong
  2021-03-15 11:57 ` [PATCH 07/35] t/v2dupindex: create_inbox Eric Wong
                   ` (28 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:57 UTC (permalink / raw)
  To: meta

Over 100ms saved and fewer LoC to boot
---
 t/xcpdb-reshard.t | 54 ++++++++++++++++++++---------------------------
 1 file changed, 23 insertions(+), 31 deletions(-)

diff --git a/t/xcpdb-reshard.t b/t/xcpdb-reshard.t
index 1b726f1a..8516b907 100644
--- a/t/xcpdb-reshard.t
+++ b/t/xcpdb-reshard.t
@@ -1,52 +1,50 @@
+#!perl -w
 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
 require_mods(qw(DBD::SQLite Search::Xapian));
 require_git('2.6');
 use PublicInbox::Eml;
-use PublicInbox::InboxWritable;
 require PublicInbox::Search;
 
-my $mime = PublicInbox::Eml->new(<<'EOF');
+my ($tmpdir, $for_destroy) = tmpdir();
+my $nproc =  8;
+my $ndoc = 13;
+my $ibx = create_inbox 'test', version => 2, indexlevel => 'medium',
+			tmpdir => "$tmpdir/testbox", nproc => $nproc, sub {
+	my ($im, $ibx) = @_;
+	my $eml = PublicInbox::Eml->new(<<'EOF');
 From: a@example.com
 To: test@example.com
 Subject: this is a subject
 Date: Fri, 02 Oct 1993 00:00:00 +0000
 
 EOF
-my ($this) = (split('/', $0))[-1];
-my ($tmpdir, $for_destroy) = tmpdir();
-local $ENV{PI_CONFIG} = "$tmpdir/config";
-my $ibx = PublicInbox::Inbox->new({
-	inboxdir => "$tmpdir/testbox",
-	name => $this,
-	version => 2,
-	-primary_address => 'test@example.com',
-	indexlevel => 'medium',
-});
-my @xcpdb = qw(-xcpdb -q);
-my $nproc = 8;
-my $ndoc = 13;
-my $im = PublicInbox::InboxWritable->new($ibx, {nproc => $nproc})->importer;
-for my $i (1..$ndoc) {
-	$mime->header_set('Message-ID', "<m$i\@example.com>");
-	ok($im->add($mime), "message $i added");
-}
-$im->done;
+	for my $i (1..$ndoc) {
+		$eml->header_set('Message-ID', "<m$i\@example.com>");
+		ok($im->add($eml), "message $i added");
+	}
+	open my $fh, '>', "$ibx->{inboxdir}/empty" or BAIL_OUT "open $!";
+};
+my $env = { PI_CONFIG  => "$ibx->{inboxdir}/empty" };
 my @shards = grep(m!/\d+\z!, glob("$ibx->{inboxdir}/xap*/*"));
 is(scalar(@shards), $nproc - 1, 'got expected shards');
 my $orig = $ibx->over->query_xover(1, $ndoc);
 my %nums = map {; "$_->{num}" => 1 } @$orig;
+my @xcpdb = qw(-xcpdb -q);
 
+my $XapianDatabase = do {
+	no warnings 'once';
+	$PublicInbox::Search::X{Database};
+};
 # ensure we can go up or down in shards, or stay the same:
 for my $R (qw(2 4 1 3 3)) {
 	delete $ibx->{search}; # release old handles
 	my $cmd = [@xcpdb, "-R$R", $ibx->{inboxdir}];
 	push @$cmd, '--compact' if $R == 1 && have_xapian_compact;
-	ok(run_script($cmd), "xcpdb -R$R");
+	ok(run_script($cmd, $env), "xcpdb -R$R");
 	my @new_shards = grep(m!/\d+\z!, glob("$ibx->{inboxdir}/xap*/*"));
 	is(scalar(@new_shards), $R, 'resharded to two shards');
 	my $mset = $ibx->search->mset('s:this');
@@ -60,10 +58,6 @@ for my $R (qw(2 4 1 3 3)) {
 	# ensure docids in Xapian match NNTP article numbers
 	my $tot = 0;
 	my %tmp = %nums;
-	my $XapianDatabase = do {
-		no warnings 'once';
-		$PublicInbox::Search::X{Database};
-	};
 	foreach my $d (@new_shards) {
 		my $xdb = $XapianDatabase->new($d);
 		$tot += $xdb->get_doccount;
@@ -78,6 +72,4 @@ for my $R (qw(2 4 1 3 3)) {
 	}
 	is(scalar keys %tmp, 0, 'all docids seen');
 }
-
-done_testing();
-1;
+done_testing;

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

* [PATCH 07/35] t/v2dupindex: create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (5 preceding siblings ...)
  2021-03-15 11:57 ` [PATCH 06/35] t/xcpdb-reshard: " Eric Wong
@ 2021-03-15 11:57 ` Eric Wong
  2021-03-15 11:57 ` [PATCH 08/35] t/admin: switch to create_inbox Eric Wong
                   ` (27 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:57 UTC (permalink / raw)
  To: meta

Another hundred milliseconds or so saved.
---
 t/v2dupindex.t | 76 +++++++++++++++++++++++++-------------------------
 1 file changed, 38 insertions(+), 38 deletions(-)

diff --git a/t/v2dupindex.t b/t/v2dupindex.t
index 4b20c8e0..3339cc10 100644
--- a/t/v2dupindex.t
+++ b/t/v2dupindex.t
@@ -4,49 +4,49 @@
 
 # we can index a message from a mirror which bypasses dedupe.
 use strict;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
+use PublicInbox::Git;
 require_git(2.6);
 require_mods(qw(DBD::SQLite));
 my ($tmpdir, $for_destroy) = tmpdir();
-use_ok 'PublicInbox::Import';
-use_ok 'PublicInbox::Git';
-use_ok 'PublicInbox::InboxWritable';
-my $ibx = PublicInbox::InboxWritable->new({
-	inboxdir => $tmpdir,
-	name => 'test-v2dupindex',
-	version => 2,
-	indexlevel => 'basic',
-	-primary_address => 'test@example.com',
-}, { nproc => 1 });
-$ibx->init_inbox(1);
-my $v2w = $ibx->importer;
-$v2w->add(eml_load('t/plack-qp.eml'));
-$v2w->add(eml_load('t/mda-mime.eml'));
-$v2w->done;
-
-my $git0 = PublicInbox::Git->new("$tmpdir/git/0.git");
-my $im = PublicInbox::Import->new($git0, undef, undef, $ibx);
-$im->{path_type} = 'v2';
-$im->{lock_path} = undef;
-
-# bypass duplicate filters (->header_set is optional)
-my $eml = eml_load('t/plack-qp.eml');
-$eml->header_set('X-This-Is-Not-Checked-By-ContentHash', 'blah');
-ok($im->add($eml), 'add seen message directly');
-ok($im->add(eml_load('t/mda-mime.eml')), 'add another seen message directly');
-
-ok($im->add(eml_load('t/iso-2202-jp.eml')), 'add another new message');
-$im->done;
-
-# mimic a fresh clone by dropping indices
-my @sqlite = (glob("$tmpdir/*sqlite3*"), glob("$tmpdir/xap*/*sqlite3*"));
-is(unlink(@sqlite), scalar(@sqlite), 'unlinked SQLite indices');
-my @shards = glob("$tmpdir/xap*/?");
-is(scalar(@shards), 0, 'no Xapian shards to drop');
-
+my $inboxdir = "$tmpdir/test";
+my $ibx = create_inbox('test', indexlevel => 'basic', version => 2,
+		tmpdir => $inboxdir, sub {
+	my ($im, $ibx) = @_;
+	$im->add(eml_load('t/plack-qp.eml'));
+	$im->add(eml_load('t/mda-mime.eml'));
+	$im->done;
+
+	# bypass duplicate filters (->header_set is optional)
+	my $git0 = PublicInbox::Git->new("$ibx->{inboxdir}/git/0.git");
+	$_[0] = undef;
+	$im = PublicInbox::Import->new($git0, undef, undef, $ibx);
+	$im->{path_type} = 'v2';
+	$im->{lock_path} = undef;
+
+	my $eml = eml_load('t/plack-qp.eml');
+	$eml->header_set('X-This-Is-Not-Checked-By-ContentHash', 'blah');
+	$im->add($eml) or BAIL_OUT 'add seen message directly';
+	$im->add(eml_load('t/mda-mime.eml')) or
+		BAIL_OUT 'add another seen message directly';
+	$im->add(eml_load('t/iso-2202-jp.eml')) or
+		BAIL_OUT 'add another new message';
+	$im->done;
+	# mimic a fresh clone by dropping indices
+	my $dir = $ibx->{inboxdir};
+	my @sqlite = (glob("$dir/*sqlite3*"), glob("$dir/xap*/*sqlite3*"));
+	unlink(@sqlite) == scalar(@sqlite) or
+			BAIL_OUT 'did not unlink SQLite indices';
+	my @shards = glob("$dir/xap*/?");
+	scalar(@shards) == 0 or BAIL_OUT 'Xapian shards created unexpectedly';
+	open my $fh, '>', "$dir/empty" or BAIL_OUT;
+	rmdir($_) for glob("$dir/xap*");
+});
+my $env = { PI_CONFIG => "$inboxdir/empty" };
 my $rdr = { 2 => \(my $err = '') };
-ok(run_script([qw(-index -Lbasic), $tmpdir], undef, $rdr), '-indexed');
+ok(run_script([qw(-index -Lbasic), $inboxdir ], $env, $rdr), '-indexed');
 my @n = $ibx->over->dbh->selectrow_array('SELECT COUNT(*) FROM over');
 is_deeply(\@n, [ 3 ], 'identical message not re-indexed');
 my $mm = $ibx->mm->{dbh}->selectall_arrayref(<<'');

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

* [PATCH 08/35] t/admin: switch to create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (6 preceding siblings ...)
  2021-03-15 11:57 ` [PATCH 07/35] t/v2dupindex: create_inbox Eric Wong
@ 2021-03-15 11:57 ` Eric Wong
  2021-03-15 19:51   ` [SQUASH] " Eric Wong
  2021-03-15 11:58 ` [PATCH 09/35] t/html_index: remove now-worthless test Eric Wong
                   ` (26 subsequent siblings)
  34 siblings, 1 reply; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:57 UTC (permalink / raw)
  To: meta

Over 100ms saved.
---
 t/admin.t | 38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/t/admin.t b/t/admin.t
index fbfcd6d3..4402c5ae 100644
--- a/t/admin.t
+++ b/t/admin.t
@@ -1,17 +1,26 @@
+#!perl -w
 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
 use PublicInbox::Import;
 use_ok 'PublicInbox::Admin';
+my $v1 = create_inbox 'v1', sub {};
 my ($tmpdir, $for_destroy) = tmpdir();
-my $git_dir = "$tmpdir/v1";
-my $v2_dir = "$tmpdir/v2";
+my $git_dir = $v1->{inboxdir};
 my ($res, $err, $v);
+my $v2ibx;
+SKIP: {
+	require_mods(qw(DBD::SQLite), 5);
+	require_git(2.6, 1) or skip 5, 'git too old';
+	$v2ibx = create_inbox 'v2', indexlevel => 'basic', version => 2, sub {
+		my ($v2w, $ibx) = @_;
+		$v2w->idx_init;
+		$v2w->importer;
+	};
+};
 
-PublicInbox::Import::init_bare($git_dir);
 *resolve_inboxdir = \&PublicInbox::Admin::resolve_inboxdir;
 
 # v1
@@ -51,22 +60,8 @@ SKIP: {
 }
 
 # v2
-SKIP: {
-	for my $m (qw(DBD::SQLite)) {
-		skip "$m missing", 5 unless eval "require $m";
-	}
-	use_ok 'PublicInbox::V2Writable';
-	use_ok 'PublicInbox::Inbox';
-	my $ibx = PublicInbox::Inbox->new({
-			inboxdir => $v2_dir,
-			name => 'test-v2writable',
-			version => 2,
-			-primary_address => 'test@example.com',
-			indexlevel => 'basic',
-		});
-	PublicInbox::V2Writable->new($ibx, 1)->idx_init;
-
-	ok(-e "$v2_dir/inbox.lock", 'exists');
+if ($v2ibx) {
+	my $v2_dir = $v2ibx->{inboxdir};
 	is(resolve_inboxdir($v2_dir), $v2_dir,
 		'resolve_inboxdir works on v2_dir');
 	chdir($v2_dir) or BAIL_OUT "chdir v2_dir: $!";
@@ -76,7 +71,6 @@ SKIP: {
 	is($res, $v2_dir, 'detects directory along with version');
 
 	# TODO: should work from inside Xapian dirs, and git dirs, here...
-	PublicInbox::Import::init_bare("$v2_dir/git/0.git");
 	my $objdir = "$v2_dir/git/0.git/objects";
 	is($v2_dir, resolve_inboxdir($objdir, \$v), 'at $objdir');
 	is($v, 2, 'version 2 detected at $objdir');

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

* [PATCH 09/35] t/html_index: remove now-worthless test
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (7 preceding siblings ...)
  2021-03-15 11:57 ` [PATCH 08/35] t/admin: switch to create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 10/35] t/plack: use create_inbox Eric Wong
                   ` (25 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

This was for quote-folding behavior we had long ago, but
it ended up just being yet another import test.
---
 MANIFEST       |  1 -
 t/html_index.t | 56 --------------------------------------------------
 2 files changed, 57 deletions(-)
 delete mode 100644 t/html_index.t

diff --git a/MANIFEST b/MANIFEST
index 4d2cfb10..49c10d62 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -345,7 +345,6 @@ t/hl_mod.t
 t/home2/.gitignore
 t/home2/Makefile
 t/home2/README
-t/html_index.t
 t/httpd-corner.psgi
 t/httpd-corner.t
 t/httpd-https.t
diff --git a/t/html_index.t b/t/html_index.t
deleted file mode 100644
index 8e2a674f..00000000
--- a/t/html_index.t
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
-# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use warnings;
-use Test::More;
-use PublicInbox::Eml;
-use PublicInbox::Feed;
-use PublicInbox::Git;
-use PublicInbox::Import;
-use PublicInbox::Inbox;
-use PublicInbox::TestCommon;
-my ($tmpdir, $for_destroy) = tmpdir();
-my $git_dir = "$tmpdir/gittest";
-my $ibx = PublicInbox::Inbox->new({
-	address => 'test@example',
-	name => 'tester',
-	inboxdir => $git_dir,
-	url => 'http://example.com/test',
-});
-my $git = $ibx->git;
-my $im = PublicInbox::Import->new($git, 'tester', 'test@example');
-
-# setup
-{
-	$im->init_bare;
-	my $prev = "";
-
-	foreach my $i (1..6) {
-		my $mid = "<$i\@example.com>";
-		my $mid_line = "Message-ID: $mid";
-		if ($prev) {
-			$mid_line .= "In-Reply-To: $prev";
-		}
-		$prev = $mid;
-		my $mime = PublicInbox::Eml->new(<<EOF);
-From: ME <me\@example.com>
-To: U <u\@example.com>
-$mid_line
-Subject: zzz #$i
-Date: Thu, 01 Jan 1970 00:00:00 +0000
-
-> This is a long multi line quote so it should not be allowed to
-> show up in its entirty in the Atom feed.  drop me
-
-msg $i
-
-> inline me here, short quote
-
-keep me
-EOF
-		like($im->add($mime), qr/\A:\d+\z/, 'inserted message');
-	}
-	$im->done;
-}
-
-done_testing();

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

* [PATCH 10/35] t/plack: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (8 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 09/35] t/html_index: remove now-worthless test Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 11/35] t/psgi_attach: convert to create_inbox Eric Wong
                   ` (24 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Only a few dozen milliseconds saved, but better than nothing.
---
 t/plack.t | 69 +++++++++++++++++++++----------------------------------
 1 file changed, 26 insertions(+), 43 deletions(-)

diff --git a/t/plack.t b/t/plack.t
index 8d8aa100..db72e6cc 100644
--- a/t/plack.t
+++ b/t/plack.t
@@ -1,37 +1,20 @@
+#!perl -w
 # Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
 my $psgi = "./examples/public-inbox.psgi";
-my ($tmpdir, $for_destroy) = tmpdir();
-my $pi_config = "$tmpdir/config";
-my $inboxdir = "$tmpdir/main.git";
-my $addr = 'test-public@example.com';
 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape);
 require_mods(@mods);
-use_ok 'PublicInbox::Import';
-use_ok 'PublicInbox::Git';
-my @ls;
-
 foreach my $mod (@mods) { use_ok $mod; }
-local $ENV{PI_CONFIG} = $pi_config;
 ok(-f $psgi, "psgi example file found");
 my $pfx = 'http://example.com/test';
-ok(run_script(['-init', 'test', $inboxdir, "$pfx/", $addr]),
-	'initialized repo');
-xsys_e(qw(git config -f), $pi_config,
-	qw(publicinbox.test.newsgroup inbox.test));
-open my $fh, '>', "$inboxdir/description" or die "open: $!\n";
-print $fh "test for public-inbox\n";
-close $fh or die "close: $!\n";
-my $app = require $psgi;
-my $git = PublicInbox::Git->new($inboxdir);
-my $im = PublicInbox::Import->new($git, 'test', $addr);
 # ensure successful message delivery
-{
-	my $mime = PublicInbox::Eml->new(<<EOF);
+my $ibx = create_inbox('test', sub {
+	my ($im, $ibx) = @_;
+	my $addr = $ibx->{-primary_address};
+	$im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT '->add';
 From: Me <me\@example.com>
 To: You <you\@example.com>
 Cc: $addr
@@ -42,26 +25,14 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 > quoted text
 zzzzzz
 EOF
-	$im->add($mime);
-	$im->done;
-	my $rev = $git->qx(qw(rev-list HEAD));
-	like($rev, qr/\A[a-f0-9]{40,}/, "good revision committed");
-	@ls = $git->qx(qw(ls-tree -r --name-only HEAD));
-	chomp @ls;
-
 	# multipart with two text bodies
-	$mime = eml_load 't/plack-2-txt-bodies.eml';
-	$im->add($mime);
+	$im->add(eml_load('t/plack-2-txt-bodies.eml')) or BAIL_OUT '->add';
 
 	# multipart with attached patch + filename
-	$mime = eml_load 't/plack-attached-patch.eml';
-	$im->add($mime);
+	$im->add(eml_load('t/plack-attached-patch.eml')) or BAIL_OUT '->add';
 
 	# multipart collapsed to single quoted-printable text/plain
-	$mime = eml_load 't/plack-qp.eml';
-	like($mime->body_raw, qr/hi =3D bye=/, 'our test used QP correctly');
-	$im->add($mime);
-
+	$im->add(eml_load('t/plack-qp.eml')) or BAIL_OUT '->add';
 	my $crlf = <<EOF;
 From: Me
   <me\@example.com>
@@ -77,11 +48,24 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 :(
 EOF
 	$crlf =~ s/\n/\r\n/sg;
-	$im->add(PublicInbox::Eml->new($crlf));
+	$im->add(PublicInbox::Eml->new($crlf)) or BAIL_OUT '->add';
 
-	$im->done;
-}
+	open my $fh, '>', "$ibx->{inboxdir}/description" or BAIL_OUT "open: $!";
+	print $fh "test for public-inbox\n" or BAIL_OUT;
+	close $fh or BAIL_OUT "close: $!";
+	open $fh, '>', "$ibx->{inboxdir}/pi_config";
+	print $fh <<EOF or BAIL_OUT;
+[publicinbox "test"]
+	inboxdir = $ibx->{inboxdir}
+	newsgroup = inbox.test
+	address = $addr
+	url = $pfx/
+EOF
+	close $fh or BAIL_OUT "close: $!";
+});
 
+local $ENV{PI_CONFIG} = "$ibx->{inboxdir}/pi_config";
+my $app = require $psgi;
 test_psgi($app, sub {
 	my ($cb) = @_;
 	foreach my $u (qw(robots.txt favicon.ico .well-known/foo)) {
@@ -259,8 +243,7 @@ test_psgi($app, sub {
 	# for a while, we used to support /$INBOX/$X40/
 	# when we "compressed" long Message-IDs to SHA-1
 	# Now we're stuck supporting them forever :<
-	foreach my $path (@ls) {
-		$path =~ tr!/!!d;
+	foreach my $path ('f2912279bd7bcd8b7ab3033234942d58746d56f7') {
 		my $from = "http://example.com/test/$path/";
 		my $res = $cb->(GET($from));
 		is(301, $res->code, 'is permanent redirect');

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

* [PATCH 11/35] t/psgi_attach: convert to create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (9 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 10/35] t/plack: use create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 12/35] t/httpd: " Eric Wong
                   ` (23 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Another few dozen milliseconds saved.
---
 t/psgi_attach.t | 56 +++++++++++++++++++++----------------------------
 1 file changed, 24 insertions(+), 32 deletions(-)

diff --git a/t/psgi_attach.t b/t/psgi_attach.t
index f53b7510..79665d6f 100644
--- a/t/psgi_attach.t
+++ b/t/psgi_attach.t
@@ -1,44 +1,37 @@
+#!perl -w
 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
-my ($tmpdir, $for_destroy) = tmpdir();
-my $inboxdir = "$tmpdir/main.git";
-my $addr = 'test-public@example.com';
 my @mods = qw(HTTP::Request::Common Plack::Builder Plack::Test URI::Escape);
 require_mods(@mods);
 use_ok $_ foreach @mods;
 use_ok 'PublicInbox::WWW';
-use PublicInbox::Import;
-use PublicInbox::Git;
 use PublicInbox::Config;
 use PublicInbox::Eml;
 use_ok 'PublicInbox::WwwAttach';
-
-my $cfgpath = "$tmpdir/config";
-open my $fh, '>', $cfgpath or BAIL_OUT $!;
-print $fh <<EOF or BAIL_OUT $!;
+my $cfgpath;
+my $creat_cb = sub {
+	my ($im, $ibx) = @_;
+	$im->add(eml_load('t/psgi_attach.eml')) or BAIL_OUT;
+	$im->add(eml_load('t/data/message_embed.eml')) or BAIL_OUT;
+	$cfgpath = "$ibx->{inboxdir}/pi_config";
+	open my $fh, '>', $cfgpath or BAIL_OUT $!;
+	print $fh <<EOF or BAIL_OUT $!;
 [publicinbox "test"]
-	address = $addr
-	inboxdir = $inboxdir
+	address = $ibx->{-primary_address}
+	inboxdir = $ibx->{inboxdir}
 EOF
-close $fh or BAIL_OUT $!;
-my $config = PublicInbox::Config->new($cfgpath);
-my $git = PublicInbox::Git->new($inboxdir);
-my $im = PublicInbox::Import->new($git, 'test', $addr);
-$im->init_bare;
-
+	close $fh or BAIL_OUT $!;
+};
+my $ibx = create_inbox 'test', $creat_cb;
+$cfgpath //= "$ibx->{inboxdir}/pi_config";
 my $qp = "abcdef=g\n==blah\n";
 my $b64 = "b64\xde\xad\xbe\xef\n";
 my $txt = "plain\ntext\npass\nthrough\n";
 my $dot = "dotfile\n";
-$im->add(eml_load('t/psgi_attach.eml'));
-$im->add(eml_load('t/data/message_embed.eml'));
-$im->done;
-
-my $www = PublicInbox::WWW->new($config);
+my $www = PublicInbox::WWW->new(PublicInbox::Config->new($cfgpath));
 my $client = sub {
 	my ($cb) = @_;
 	my $res;
@@ -104,20 +97,19 @@ my $client = sub {
 
 test_psgi(sub { $www->call(@_) }, $client);
 SKIP: {
-	diag 'testing with index indexed';
-	require_mods('DBD::SQLite', 19);
+	require_mods(qw(DBD::SQLite Plack::Test::ExternalServer), 18);
+	$ibx = create_inbox 'test-indexed', indexlevel => 'basic', $creat_cb;
+	$cfgpath = "$ibx->{inboxdir}/pi_config";
 	my $env = { PI_CONFIG => $cfgpath };
-	ok(run_script(['-index', $inboxdir], $env), 'indexed');
-
+	$www = PublicInbox::WWW->new(PublicInbox::Config->new($cfgpath));
 	test_psgi(sub { $www->call(@_) }, $client);
-
-	require_mods(qw(Plack::Test::ExternalServer), 18);
 	my $sock = tcp_server() or die;
-	my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err);
+	my ($tmpdir, $for_destroy) = tmpdir();
+	my ($out, $err) = map { "$tmpdir/std$_.log" } qw(out err);
 	my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
 	my $td = start_script($cmd, $env, { 3 => $sock });
 	my ($h, $p) = tcp_host_port($sock);
 	local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
 	Plack::Test::ExternalServer::test_psgi(client => $client);
 }
-done_testing();
+done_testing;

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

* [PATCH 12/35] t/httpd: convert to create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (10 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 11/35] t/psgi_attach: convert to create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 13/35] t/convert-compact: create_inbox Eric Wong
                   ` (22 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

No real difference, here, but having less code is nice.
---
 t/httpd.t | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/t/httpd.t b/t/httpd.t
index af9fbfeb..0354a733 100644
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -1,8 +1,8 @@
+#!perl -w
 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
 use PublicInbox::Eml;
 use Socket qw(IPPROTO_TCP SOL_SOCKET);
@@ -13,22 +13,15 @@ my ($tmpdir, $for_destroy) = tmpdir();
 my $home = "$tmpdir/pi-home";
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
-my $maindir = "$tmpdir/main.git";
+my $inboxdir = "$tmpdir/i.git";
 my $group = 'test-httpd';
 my $addr = $group . '@example.com';
-my $cfgpfx = "publicinbox.$group";
 my $sock = tcp_server();
 my $td;
-use_ok 'PublicInbox::Git';
-use_ok 'PublicInbox::Import';
 {
-	local $ENV{HOME} = $home;
-	my $cmd = [ '-init', $group, $maindir, 'http://example.com/', $addr ];
-	ok(run_script($cmd), 'init ran properly');
-
-	# ensure successful message delivery
-	{
-		my $mime = PublicInbox::Eml->new(<<EOF);
+	create_inbox 'test', tmpdir => $inboxdir, sub {
+		my ($im, $ibx) = @_;
+		$im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
 From: Me <me\@example.com>
 To: You <you\@example.com>
 Cc: $addr
@@ -38,12 +31,10 @@ Date: Thu, 01 Jan 1970 06:06:06 +0000
 
 nntp
 EOF
-
-		my $git = PublicInbox::Git->new($maindir);
-		my $im = PublicInbox::Import->new($git, 'test', $addr);
-		$im->add($mime);
-		$im->done($mime);
-	}
+	};
+	local $ENV{HOME} = $home;
+	my $cmd = [ '-init', $group, $inboxdir, 'http://example.com/', $addr ];
+	ok(run_script($cmd), 'init ran properly');
 	$cmd = [ '-httpd', '-W0', "--stdout=$out", "--stderr=$err" ];
 	$td = start_script($cmd, undef, { 3 => $sock });
 	my $http_pfx = 'http://'.tcp_host_port($sock);
@@ -53,7 +44,6 @@ EOF
 		like(<$bad>, qr!\AHTTP/1\.[01] 405\b!, 'got 405 on bad req');
 	}
 	my $conn = tcp_connect($sock);
-	ok($conn, 'connected');
 	ok($conn->write("GET / HTTP/1.0\r\n\r\n"), 'wrote data to socket');
 	{
 		my $buf;
@@ -67,7 +57,7 @@ EOF
 		0, 'smart clone successful');
 
 	# ensure dumb cloning works, too:
-	is(xsys('git', "--git-dir=$maindir",
+	is(xsys('git', "--git-dir=$inboxdir",
 		qw(config http.uploadpack false)),
 		0, 'disable http.uploadpack');
 	is(xsys(qw(git clone -q --mirror),
@@ -99,6 +89,4 @@ SKIP: {
 	like($x, qr/\Ahttpready\0+\z/, 'got httpready accf for HTTP');
 };
 
-done_testing();
-
-1;
+done_testing;

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

* [PATCH 13/35] t/convert-compact: create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (11 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 12/35] t/httpd: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 14/35] t/altid: use create_inbox Eric Wong
                   ` (21 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Suprisingly, this saves over 100 milliseconds.
---
 lib/PublicInbox/TestCommon.pm |  7 +++--
 t/convert-compact.t           | 48 +++++++++++++++--------------------
 2 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 6ca69174..c2d07e59 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -593,13 +593,17 @@ sub create_inbox ($$;@) {
 	require PublicInbox::InboxWritable;
 	my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
 	my $dir = "t/data-gen/$base.$ident";
-	unless (-d $dir) {
+	my $new = !-d $dir;
+	if ($new) {
 		mkdir $dir; # may race
 		-d $dir or BAIL_OUT "$dir could not be created: $!";
 	}
 	my $lk = bless { lock_path => "$dir/creat.lock" }, 'PublicInbox::Lock';
 	$opt{inboxdir} = File::Spec->rel2abs($dir);
 	$opt{name} //= $ident;
+	my $scope = $lk->lock_for_scope;
+	my $pre_cb = delete $opt{pre_cb};
+	$pre_cb->($dir) if $pre_cb && $new;
 	$opt{-no_fsync} = 1;
 	my $no_gc = delete $opt{-no_gc};
 	my $tmpdir = delete $opt{tmpdir};
@@ -608,7 +612,6 @@ sub create_inbox ($$;@) {
 	my $parallel = delete($opt{importer_parallel}) // 0;
 	my $creat_opt = { nproc => delete($opt{nproc}) // 1 };
 	my $ibx = PublicInbox::InboxWritable->new({ %opt }, $creat_opt);
-	my $scope = $lk->lock_for_scope;
 	if (!-f "$dir/creat.stamp") {
 		my $im = $ibx->importer($parallel);
 		$cb->($im, $ibx);
diff --git a/t/convert-compact.t b/t/convert-compact.t
index cdb9e3f5..7270cab0 100644
--- a/t/convert-compact.t
+++ b/t/convert-compact.t
@@ -1,31 +1,28 @@
+#!perl -w
 # Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::Eml;
 use PublicInbox::TestCommon;
+use PublicInbox::Import;
 require_git(2.6);
 require_mods(qw(DBD::SQLite Search::Xapian));
 have_xapian_compact or
 	plan skip_all => 'xapian-compact missing for '.__FILE__;
-
-use_ok 'PublicInbox::V2Writable';
-use PublicInbox::Import;
 my ($tmpdir, $for_destroy) = tmpdir();
-my $ibx = {
-	inboxdir => "$tmpdir/v1",
-	name => 'test-v1',
-	-primary_address => 'test@example.com',
-};
-
-PublicInbox::Import::init_bare($ibx->{inboxdir});
-ok(umask(077), 'set restrictive umask');
-xsys_e(qw(git) , "--git-dir=$ibx->{inboxdir}",
-	qw(config core.sharedRepository 0644));
-$ibx = PublicInbox::Inbox->new($ibx);
-my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
-my $mime = PublicInbox::Eml->new(<<'EOF');
+my $ibx = create_inbox 'v1', indexlevel => 'medium', tmpdir => "$tmpdir/v1",
+		pre_cb => sub {
+			my ($inboxdir) = @_;
+			PublicInbox::Import::init_bare($inboxdir);
+			xsys_e(qw(git) , "--git-dir=$inboxdir",
+				qw(config core.sharedRepository 0644));
+		}, sub {
+	my ($im, $ibx) = @_;
+	$im->done;
+	umask(077) or BAIL_OUT "umask: $!";
+	$_[0] = $im = $ibx->importer(0);
+	my $eml = PublicInbox::Eml->new(<<'EOF');
 From: a@example.com
 To: b@example.com
 Subject: this is a subject
@@ -34,16 +31,11 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 
 hello world
 EOF
-
-ok($im->add($mime), 'added one message');
-ok($im->remove($mime), 'remove message');
-ok($im->add($mime), 'added message again');
-$im->done;
-for (1..2) {
-	eval { PublicInbox::SearchIdx->new($ibx, 1)->index_sync; };
-	is($@, '', 'no errors syncing');
-}
-
+	$im->add($eml) or BAIL_OUT '->add';
+	$im->remove($eml) or BAIL_OUT '->remove';
+	$im->add($eml) or BAIL_OUT '->add';
+};
+umask(077) or BAIL_OUT "umask: $!";
 is(((stat("$ibx->{inboxdir}/public-inbox"))[2]) & 07777, 0755,
 	'sharedRepository respected for v1');
 is(((stat("$ibx->{inboxdir}/public-inbox/msgmap.sqlite3"))[2]) & 07777, 0644,

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

* [PATCH 14/35] t/altid: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (12 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 13/35] t/convert-compact: create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 15/35] t/psgi_mount: switch to create_inbox Eric Wong
                   ` (20 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Another few dozen milliseconds saved.
---
 t/altid.t | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/t/altid.t b/t/altid.t
index 0e9da07e..87635b19 100644
--- a/t/altid.t
+++ b/t/altid.t
@@ -1,15 +1,13 @@
+#!perl -w
 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
 use PublicInbox::Eml;
 require_mods(qw(DBD::SQLite Search::Xapian));
 use_ok 'PublicInbox::Msgmap';
 use_ok 'PublicInbox::SearchIdx';
-use_ok 'PublicInbox::Import';
-use_ok 'PublicInbox::Inbox';
 my ($tmpdir, $for_destroy) = tmpdir();
 my $git_dir = "$tmpdir/a.git";
 my $alt_file = "$tmpdir/another-nntp.sqlite3";
@@ -24,10 +22,9 @@ my $ibx;
 }
 
 {
-	my $git = PublicInbox::Git->new($git_dir);
-	my $im = PublicInbox::Import->new($git, 'testbox', 'test@example');
-	$im->init_bare;
-	$im->add(PublicInbox::Eml->new(<<'EOF'));
+	$ibx = create_inbox 'testbox', tmpdir => $git_dir, sub {
+		my ($im) = @_;
+		$im->add(PublicInbox::Eml->new(<<'EOF'));
 From: a@example.com
 To: b@example.com
 Subject: boo!
@@ -35,13 +32,9 @@ Message-ID: <a@example.com>
 
 hello world gmane:666
 EOF
-	$im->done;
-}
-{
-	$ibx = PublicInbox::Inbox->new({inboxdir => $git_dir});
+	};
 	$ibx->{altid} = $altid;
-	my $rw = PublicInbox::SearchIdx->new($ibx, 1);
-	$rw->index_sync;
+	PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
 }
 
 {
@@ -60,7 +53,4 @@ EOF
 	my $num = $mm->mid_insert('b@example.com');
 	ok($num > $max, 'auto-increment goes beyond mid_set');
 }
-
-done_testing();
-
-1;
+done_testing;

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

* [PATCH 15/35] t/psgi_mount: switch to create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (13 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 14/35] t/altid: use create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 16/35] t/feed: " Eric Wong
                   ` (19 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

A few dozen more milliseconds saved.
---
 t/psgi_mount.t | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/t/psgi_mount.t b/t/psgi_mount.t
index 5836e9ce..e9547c15 100644
--- a/t/psgi_mount.t
+++ b/t/psgi_mount.t
@@ -1,44 +1,36 @@
+#!perl -w
 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::Eml;
 use PublicInbox::TestCommon;
+use PublicInbox::Config;
 my ($tmpdir, $for_destroy) = tmpdir();
-my $maindir = "$tmpdir/main.git";
-my $addr = 'test-public@example.com';
+my $v1dir = "$tmpdir/v1.git";
 my $cfgpfx = "publicinbox.test";
 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape
 	Plack::Builder Plack::App::URLMap);
 require_mods(@mods);
 use_ok $_ foreach @mods;
 use_ok 'PublicInbox::WWW';
-use PublicInbox::Import;
-use PublicInbox::Git;
-use PublicInbox::Config;
-my $cfg = PublicInbox::Config->new(\<<EOF);
-$cfgpfx.address=$addr
-$cfgpfx.inboxdir=$maindir
-EOF
-my $git = PublicInbox::Git->new($maindir);
-my $im = PublicInbox::Import->new($git, 'test', $addr);
-$im->init_bare;
-{
-	my $mime = PublicInbox::Eml->new(<<EOF);
+my $ibx = create_inbox 'test', tmpdir => $v1dir, sub {
+	my ($im, $ibx) = @_;
+	$im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
 From: Me <me\@example.com>
 To: You <you\@example.com>
-Cc: $addr
+Cc: $ibx->{-primary_address}
 Message-Id: <blah\@example.com>
 Subject: hihi
 Date: Thu, 01 Jan 1970 00:00:00 +0000
 
 zzzzzz
 EOF
-	$im->add($mime);
-	$im->done;
-}
-
+};
+my $cfg = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=$ibx->{-primary_address}
+$cfgpfx.inboxdir=$v1dir
+EOF
 my $www = PublicInbox::WWW->new($cfg);
 my $app = builder(sub {
 	enable('Head');
@@ -83,7 +75,6 @@ test_psgi($app, sub {
 
 SKIP: {
 	require_mods(qw(DBD::SQLite Search::Xapian IO::Uncompress::Gunzip), 3);
-	my $ibx = $cfg->lookup_name('test');
 	require_ok 'PublicInbox::SearchIdx';
 	PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
 	test_psgi($app, sub {

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

* [PATCH 16/35] t/feed: switch to create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (14 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 15/35] t/psgi_mount: switch to create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 17/35] t/psgi_bad_mids: use create_inbox Eric Wong
                   ` (18 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

This only saves a few milliseconds, but is less code.
---
 t/feed.t | 53 +++++++++++++++--------------------------------------
 1 file changed, 15 insertions(+), 38 deletions(-)

diff --git a/t/feed.t b/t/feed.t
index cdbc88cd..cc5ae277 100644
--- a/t/feed.t
+++ b/t/feed.t
@@ -1,14 +1,14 @@
+#!perl -w
 # Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
+use PublicInbox::TestCommon;
 use PublicInbox::Eml;
 use PublicInbox::Feed;
-use PublicInbox::Import;
 use PublicInbox::Inbox;
 my $have_xml_treepp = eval { require XML::TreePP; 1 };
-use PublicInbox::TestCommon;
+my ($tmpdir, $for_destroy) = tmpdir();
 
 sub string_feed {
 	my $res = PublicInbox::Feed::generate($_[0]);
@@ -21,43 +21,18 @@ sub string_feed {
 	$str;
 }
 
-my ($tmpdir, $for_destroy) = tmpdir();
 my $git_dir = "$tmpdir/gittest";
-my $ibx = PublicInbox::Inbox->new({
-	address => 'test@example',
-	name => 'testbox',
-	inboxdir => $git_dir,
-	url => [ 'http://example.com/test' ],
-	feedmax => 3,
-});
-my $git = $ibx->git;
-my $im = PublicInbox::Import->new($git, $ibx->{name}, 'test@example');
-
-{
-	$im->init_bare;
+my $ibx = create_inbox 'v1', tmpdir => $git_dir, sub {
+	my ($im, $ibx) = @_;
 	foreach my $i (1..6) {
-		my $mime = PublicInbox::Eml->new(<<EOF);
+		$im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
 From: ME <me\@example.com>
 To: U <u\@example.com>
 Message-Id: <$i\@example.com>
 Subject: zzz #$i
 Date: Thu, 01 Jan 1970 00:00:00 +0000
 
-> This is a long multi line quote so it should not be allowed to
-> show up in its entirty in the Atom feed.  drop me
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
-> I quote to much
+> drop me
 
 msg $i
 
@@ -66,10 +41,12 @@ msg $i
 
 keep me
 EOF
-		like($im->add($mime), qr/\A:\d+/, 'added');
 	}
-	$im->done;
-}
+};
+
+$ibx->{url} = [ 'http://example.com/test' ];
+$ibx->{feedmax} = 3;
+my $im = $ibx->importer(0);
 
 # spam check
 {
@@ -83,7 +60,7 @@ EOF
 				'looks like an an Atom feed');
 			is(scalar @{$t->{feed}->{entry}}, 3,
 				'parsed three entries');
-			is($t->{feed}->{id}, 'mailto:test@example',
+			is($t->{feed}->{id}, 'mailto:v1@example.com',
 				'id is set to default');
 		}
 
@@ -140,4 +117,4 @@ EOF
 	}
 }
 
-done_testing();
+done_testing;

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

* [PATCH 17/35] t/psgi_bad_mids: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (15 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 16/35] t/feed: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 18/35] t/psgi_multipart_not: " Eric Wong
                   ` (17 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Over 100ms saved and it's less code to boot.
---
 t/psgi_bad_mids.t | 46 +++++++++++++++-------------------------------
 1 file changed, 15 insertions(+), 31 deletions(-)

diff --git a/t/psgi_bad_mids.t b/t/psgi_bad_mids.t
index f23680f8..f92e4f97 100644
--- a/t/psgi_bad_mids.t
+++ b/t/psgi_bad_mids.t
@@ -1,31 +1,17 @@
+#!perl -w
 # Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 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(DBD::SQLite HTTP::Request::Common Plack::Test
-		URI::Escape Plack::Builder PublicInbox::WWW);
+		URI::Escape Plack::Builder);
 require_git 2.6;
 require_mods(@mods);
 use_ok($_) for @mods;
 use_ok 'PublicInbox::WWW';
-use_ok 'PublicInbox::V2Writable';
-my ($inboxdir, $for_destroy) = tmpdir();
-my $cfgpfx = "publicinbox.bad-mids";
-my $ibx = {
-	inboxdir => $inboxdir,
-	name => 'bad-mids',
-	version => 2,
-	-primary_address => 'test@example.com',
-	indexlevel => 'basic',
-};
-$ibx = PublicInbox::Inbox->new($ibx);
-my $im = PublicInbox::V2Writable->new($ibx, 1);
-$im->{parallel} = 0;
-
 my $msgs = <<'';
 F1V5OR6NMF.3M649JTLO9IXD@tux.localdomain/hehe1"'<foo
 F1V5NB0PTU.3U0DCVGAJ750Z@tux.localdomain"'<>/foo
@@ -36,25 +22,25 @@ F1V58X3CMU.2DCCVAKQZGADV@tux.localdomain/../../../../foo
 F1TVKINT3G.2S6I36MXMHYG6@tux.localdomain" onclick="alert(1)"
 
 my @mids = split(/\n/, $msgs);
-my $i = 0;
-foreach my $mid (@mids) {
-	my $data = << "";
+my $ibx = create_inbox 'bad-mids', version => 2, indexlevel => 'basic', sub {
+	my ($im) = @_;
+	my $i = 0;
+	for my $mid (@mids) {
+		$im->add(PublicInbox::Eml->new(<<"")) or BAIL_OUT;
 Subject: test
 Message-ID: <$mid>
 From: a\@example.com
 To: b\@example.com
 Date: Fri, 02 Oct 1993 00:00:0$i +0000
 
+		$i++;
+	}
+};
 
-	my $mime = PublicInbox::Eml->new(\$data);
-	ok($im->add($mime), "added $mid");
-	$i++
-}
-$im->done;
-
+my $cfgpfx = "publicinbox.bad-mids";
 my $cfg = <<EOF;
 $cfgpfx.address=$ibx->{-primary_address}
-$cfgpfx.inboxdir=$inboxdir
+$cfgpfx.inboxdir=$ibx->{inboxdir}
 EOF
 my $config = PublicInbox::Config->new(\$cfg);
 my $www = PublicInbox::WWW->new($config);
@@ -84,6 +70,4 @@ test_psgi(sub { $www->call(@_) }, sub {
 	}
 });
 
-done_testing();
-
-1;
+done_testing;

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

* [PATCH 18/35] t/psgi_multipart_not: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (16 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 17/35] t/psgi_bad_mids: use create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 19/35] t/psgi_scan_all: create_inbox lots saved Eric Wong
                   ` (16 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Over 100ms saved.
---
 t/psgi_multipart_not.t | 35 ++++++++++-------------------------
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/t/psgi_multipart_not.t b/t/psgi_multipart_not.t
index 8edbe088..5f4c06b7 100644
--- a/t/psgi_multipart_not.t
+++ b/t/psgi_multipart_not.t
@@ -1,29 +1,20 @@
+#!perl -w
 # Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
+use PublicInbox::TestCommon;
 use PublicInbox::Eml;
 use PublicInbox::Config;
-use PublicInbox::TestCommon;
 require_git 2.6;
 my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common
               Plack::Test URI::Escape Plack::Builder Plack::Test);
 require_mods(@mods);
 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
 use_ok 'PublicInbox::WWW';
-use_ok 'PublicInbox::V2Writable';
-my ($repo, $for_destroy) = tmpdir();
-my $ibx = PublicInbox::Inbox->new({
-	inboxdir => $repo,
-	name => 'multipart-not',
-	version => 2,
-	-primary_address => 'test@example.com',
-});
-my $im = PublicInbox::V2Writable->new($ibx, 1);
-$im->{parallel} = 0;
-
-my $mime = PublicInbox::Eml->new(<<'EOF');
+my $ibx = create_inbox 'v2', version => 2, sub {
+	my ($im) = @_;
+	$im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
 Message-Id: <200308111450.h7BEoOu20077@mail.osdl.org>
 To: linux-kernel@vger.kernel.org
 Subject: [OSDL] linux-2.6.0-test3 reaim results
@@ -36,17 +27,13 @@ From: exmh user <x@example.com>
 Freed^Wmultipart ain't what it used to be
 EOF
 
-ok($im->add($mime), 'added broken multipart message');
-$im->done;
-
+};
 my $cfgpfx = "publicinbox.v2test";
 my $cfg = <<EOF;
 $cfgpfx.address=$ibx->{-primary_address}
-$cfgpfx.inboxdir=$repo
+$cfgpfx.inboxdir=$ibx->{inboxdir}
 EOF
-my $config = PublicInbox::Config->new(\$cfg);
-my $www = PublicInbox::WWW->new($config);
-
+my $www = PublicInbox::WWW->new(PublicInbox::Config->new(\$cfg));
 my ($res, $raw);
 test_psgi(sub { $www->call(@_) }, sub {
 	my ($cb) = @_;
@@ -58,6 +45,4 @@ test_psgi(sub { $www->call(@_) }, sub {
 		ok(index($raw, 'Warning: decoded text') >= 0, $u.' warns');
 	}
 });
-
-done_testing();
-1;
+done_testing;

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

* [PATCH 19/35] t/psgi_scan_all: create_inbox lots saved
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (17 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 18/35] t/psgi_multipart_not: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 20/35] t/psgi_v2: create_inbox Eric Wong
                   ` (15 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

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 <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 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(<<EOF);
+	my $ibx = create_inbox "test-$i", version => 2, indexlevel => 'basic',
+	sub {
+		my ($im, $ibx) = @_;
+		$im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
 From: a\@example.com
-To: $addr
+To: $ibx->{-primary_address}
 Subject: s$i
 Message-ID: <a-mid-$i\@b>
 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;

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

* [PATCH 20/35] t/psgi_v2: create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (18 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 19/35] t/psgi_scan_all: create_inbox lots saved Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 21/35] t/imapd: create_inbox (minor) Eric Wong
                   ` (14 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Some lines of code and a dozen milliseconds dealth with.
---
 t/psgi_v2.t | 134 ++++++++++++++++++++++++----------------------------
 1 file changed, 63 insertions(+), 71 deletions(-)

diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 81355f04..487317b6 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -1,8 +1,8 @@
+#!perl -w
 # Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
 require_git(2.6);
 use PublicInbox::Eml;
@@ -12,18 +12,48 @@ require_mods(qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
 		URI::Escape Plack::Builder));
 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
 use_ok 'PublicInbox::WWW';
-use_ok 'PublicInbox::V2Writable';
-my ($inboxdir, $for_destroy) = tmpdir();
-my $cfgpath = "$inboxdir/$$.config";
-SKIP: {
-	require_mods(qw(Plack::Test::ExternalServer), 1);
+my ($tmpdir, $for_destroy) = tmpdir();
+my $eml = PublicInbox::Eml->new(<<'EOF');
+From oldbug-pre-a0c07cba0e5d8b6a Fri Oct  2 00:00:00 1993
+From: a@example.com
+To: test@example.com
+Subject: this is a subject
+Message-ID: <a-mid@b>
+Date: Fri, 02 Oct 1993 00:00:00 +0000
+
+hello world
+EOF
+my $new_mid;
+my $ibx = create_inbox 'v2', version => 2, indexlevel => 'medium',
+			tmpdir => "$tmpdir/v2", sub {
+	my ($im, $ibx) = @_;
+	$im->add($eml) or BAIL_OUT;
+	$eml->body_set("hello world!\n");
+	my @warn;
+	local $SIG{__WARN__} = sub { push @warn, @_ };
+	$eml->header_set(Date => 'Fri, 02 Oct 1993 00:01:00 +0000');
+	$im->add($eml) or BAIL_OUT;
+	is(scalar(@warn), 1, 'got one warning');
+	my $mids = mids($eml->header_obj);
+	$new_mid = $mids->[1];
+	open my $fh, '>', "$ibx->{inboxdir}/new_mid" or BAIL_OUT;
+	print $fh $new_mid or BAIL_OUT;
+	close $fh or BAIL_OUT;
+};
+$new_mid //= do {
+	open my $fh, '<', "$ibx->{inboxdir}/new_mid" or BAIL_OUT;
+	local $/;
+	<$fh>;
+};
+my $cfgpath = "$ibx->{inboxdir}/pi_config";
+{
 	open my $fh, '>', $cfgpath or BAIL_OUT $!;
 	print $fh <<EOF or BAIL_OUT $!;
 [publicinbox "v2test"]
-	inboxdir = $inboxdir
-	address = test\@example.com
+	inboxdir = $ibx->{inboxdir}
+	address = $ibx->{-primary_address}
 EOF
-	close $fh or BAIL_OUT $!;
+	close $fh or BAIL_OUT;
 }
 
 my $run_httpd = sub {
@@ -32,7 +62,7 @@ my $run_httpd = sub {
 		require_mods(qw(Plack::Test::ExternalServer), $skip);
 		my $env = { PI_CONFIG => $cfgpath };
 		my $sock = tcp_server() or die;
-		my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err);
+		my ($out, $err) = map { "$tmpdir/std$_.log" } qw(out err);
 		my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
 		my $td = start_script($cmd, $env, { 3 => $sock });
 		my ($h, $p) = tcp_host_port($sock);
@@ -47,50 +77,10 @@ my $run_httpd = sub {
 		is($e, '', 'no errors');
 	}
 };
-
-my $ibx = {
-	inboxdir => $inboxdir,
-	name => 'test-v2writable',
-	version => 2,
-	-primary_address => 'test@example.com',
-};
-$ibx = PublicInbox::Inbox->new($ibx);
-my $new_mid;
-
-my $im = PublicInbox::V2Writable->new($ibx, 1);
-$im->{parallel} = 0;
-
-my $mime = PublicInbox::Eml->new(<<'EOF');
-From oldbug-pre-a0c07cba0e5d8b6a Fri Oct  2 00:00:00 1993
-From: a@example.com
-To: test@example.com
-Subject: this is a subject
-Message-ID: <a-mid@b>
-Date: Fri, 02 Oct 1993 00:00:00 +0000
-
-hello world
-EOF
-ok($im->add($mime), 'added one message');
-$mime->body_set("hello world!\n");
-
-my @warn;
-local $SIG{__WARN__} = sub { push @warn, @_ };
-$mime->header_set(Date => 'Fri, 02 Oct 1993 00:01:00 +0000');
-ok($im->add($mime), 'added duplicate-but-different message');
-is(scalar(@warn), 1, 'got one warning');
-my $mids = mids($mime->header_obj);
-$new_mid = $mids->[1];
-$im->done;
-
 my $msg = $ibx->msg_by_mid('a-mid@b');
 like($$msg, qr/\AFrom oldbug/s,
 	'"From_" line stored to test old bug workaround');
-
-my $cfgpfx = "publicinbox.v2test";
-my $cfg = PublicInbox::Config->new(\<<EOF);
-$cfgpfx.address=$ibx->{-primary_address}
-$cfgpfx.inboxdir=$inboxdir
-EOF
+my $cfg = PublicInbox::Config->new($cfgpath);
 my $www = PublicInbox::WWW->new($cfg);
 my ($res, $raw, @from_);
 my $client0 = sub {
@@ -127,14 +117,17 @@ my $client0 = sub {
 test_psgi(sub { $www->call(@_) }, $client0);
 $run_httpd->($client0, 9);
 
-$mime->header_set('Message-Id', 'a-mid@b');
-$mime->body_set("hello ghosts\n");
-ok($im->add($mime), 'added 3rd duplicate-but-different message');
-is(scalar(@warn), 2, 'got another warning');
-like($warn[0], qr/mismatched/, 'warned about mismatched messages');
-is($warn[0], $warn[1], 'both warnings are the same');
-
-$mids = mids($mime->header_obj);
+$eml->header_set('Message-ID', 'a-mid@b');
+$eml->body_set("hello ghosts\n");
+my $im = $ibx->importer(0);
+{
+	my @warn;
+	local $SIG{__WARN__} = sub { push @warn, @_ };
+	ok($im->add($eml), 'added 3rd duplicate-but-different message');
+	is(scalar(@warn), 1, 'got another warning');
+	like($warn[0], qr/mismatched/, 'warned about mismatched messages');
+}
+my $mids = mids($eml->header_obj);
 my $third = $mids->[-1];
 $im->done;
 
@@ -236,12 +229,12 @@ $run_httpd->($client1, 38);
 
 {
 	my $exp = [ qw(<a-mid@b> <reuse@mid>) ];
-	$mime->header_set('Message-Id', @$exp);
-	$mime->header_set('Subject', '4th dupe');
+	$eml->header_set('Message-Id', @$exp);
+	$eml->header_set('Subject', '4th dupe');
 	local $SIG{__WARN__} = sub {};
-	ok($im->add($mime), 'added one message');
+	ok($im->add($eml), 'added one message');
 	$im->done;
-	my @h = $mime->header('Message-ID');
+	my @h = $eml->header('Message-ID');
 	is_deeply($exp, \@h, 'reused existing Message-ID');
 	$cfg->each_inbox(sub { $_[0]->search->reopen });
 }
@@ -277,13 +270,13 @@ test_psgi(sub { $www->call(@_) }, $client2);
 $run_httpd->($client2, 8);
 {
 	# ensure conflicted attachments can be resolved
+	local $SIG{__WARN__} = sub {};
 	foreach my $body (qw(old new)) {
-		$mime = eml_load "t/psgi_v2-$body.eml";
-		ok($im->add($mime), "added attachment $body");
+		$im->add(eml_load "t/psgi_v2-$body.eml") or BAIL_OUT;
 	}
 	$im->done;
-	$cfg->each_inbox(sub { $_[0]->search->reopen });
 }
+$cfg->each_inbox(sub { $_[0]->search->reopen });
 
 my $client3 = sub {
 	my ($cb) = @_;
@@ -299,13 +292,12 @@ my $client3 = sub {
 	}
 	$res = $cb->(GET('/v2test/?t=1970'.'01'.'01'.'000000'));
 	is($res->code, 404, '404 for out-of-range t= param');
-	@warn = ();
+	my @warn = ();
+	local $SIG{__WARN__} = sub { push @warn, @_ };
 	$res = $cb->(GET('/v2test/?t=1970'.'01'.'01'));
 	is_deeply(\@warn, [], 'no warnings on YYYYMMDD only');
 };
 test_psgi(sub { $www->call(@_) }, $client3);
 $run_httpd->($client3, 4);
 
-done_testing();
-
-1;
+done_testing;

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

* [PATCH 21/35] t/imapd: create_inbox (minor)
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (19 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 20/35] t/psgi_v2: create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 22/35] t/solver_git: use create_inbox Eric Wong
                   ` (13 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

This saves over 100ms.
---
 t/imapd.t | 66 ++++++++++++++++++++++++++-----------------------------
 1 file changed, 31 insertions(+), 35 deletions(-)

diff --git a/t/imapd.t b/t/imapd.t
index f1b498a7..c9911d1b 100644
--- a/t/imapd.t
+++ b/t/imapd.t
@@ -31,30 +31,32 @@ push(@V, 2) if require_git('2.6', 1);
 
 my ($tmpdir, $for_destroy) = tmpdir();
 my $home = "$tmpdir/home";
-local $ENV{HOME} = $home;
-
+BAIL_OUT "mkdir: $!" unless (mkdir($home) and mkdir("$home/.public-inbox"));
+my @ibx;
+open my $cfgfh, '>', "$home/.public-inbox/config" or BAIL_OUT;
+print $cfgfh <<EOM or BAIL_OUT;
+[publicinboxmda]
+	spamcheck = none
+EOM
+my $eml;
 for my $V (@V) {
-	my $addr = "i$V\@example.com";
-	my $name = "i$V";
-	my $url = "http://example.com/i$V";
-	my $inboxdir = "$tmpdir/$name";
-	my $folder = "inbox.i$V";
-	my $cmd = ['-init', "-V$V", "-L$level", "--ng=$folder",
-		$name, $inboxdir, $url, $addr];
-	run_script($cmd) or BAIL_OUT("init $name");
-	if ($V == 1) {
-		xsys(qw(git config), "--file=$ENV{HOME}/.public-inbox/config",
-			'publicinboxmda.spamcheck', 'none') == 0 or
-			BAIL_OUT("config: $?");
-	}
-	open(my $fh, '<', 't/utf8.eml') or BAIL_OUT("open t/utf8.eml: $!");
-	my $env = { ORIGINAL_RECIPIENT => $addr };
-	run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or
-		BAIL_OUT('-mda delivery');
-	if ($V == 1) {
-		run_script(['-index', $inboxdir]) or BAIL_OUT("index $?");
-	}
+	my $ibx = create_inbox("i$V", tmpdir => "$tmpdir/i$V", version => $V,
+				indexlevel => $level, sub {
+		my ($im) = @_;
+		$im->add($eml //= eml_load('t/utf8.eml')) or BAIL_OUT;
+	});
+	push @ibx, $ibx;
+	$ibx->{newsgroup} = "inbox.i$V";
+	print $cfgfh <<EOF or BAIL_OUT;
+[publicinbox "i$V"]
+	inboxdir = $ibx->{inboxdir}
+	address = $ibx->{-primary_address};
+	newsgroup = inbox.i$V
+	url = http://example.com/i$V
+EOF
 }
+close $cfgfh or BAIL_OUT;
+local $ENV{HOME} = $home;
 my $sock = tcp_server();
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
@@ -248,10 +250,7 @@ ok($mic->logout, 'logout works');
 
 my $have_inotify = eval { require Linux::Inotify2; 1 };
 
-my $pi_cfg = PublicInbox::Config->new;
-$pi_cfg->each_inbox(sub {
-	my ($ibx) = @_;
-	my $env = { ORIGINAL_RECIPIENT => $ibx->{-primary_address} };
+for my $ibx (@ibx) {
 	my $name = $ibx->{name};
 	my $ng = $ibx->{newsgroup};
 	my $mic = $imap_client->new(%mic_opt);
@@ -263,10 +262,9 @@ $pi_cfg->each_inbox(sub {
 	ok(!$mic->idle, "IDLE fails w/o SELECT/EXAMINE $name");
 	ok($mic->examine($mb), "EXAMINE $ng succeeds");
 	ok(my $idle_tag = $mic->idle, "IDLE succeeds on $ng");
-
-	open(my $fh, '<', 't/data/message_embed.eml') or BAIL_OUT("open: $!");
-	run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or
-		BAIL_OUT('-mda delivery');
+	my $im = $ibx->importer(0);
+	$im->add(eml_load 't/data/message_embed.eml') or BAIL_OUT;
+	$im->done;
 	my $t0 = Time::HiRes::time();
 	ok(my @res = $mic->idle_data(11), "IDLE succeeds on $ng");
 	is(grep(/\A\* [0-9] EXISTS\b/, @res), 1, 'got EXISTS message');
@@ -299,9 +297,8 @@ $pi_cfg->each_inbox(sub {
 			"connection $n works after HUP");
 	}
 
-	open($fh, '<', 't/data/0001.patch') or BAIL_OUT("open: $!");
-	run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or
-		BAIL_OUT('-mda delivery');
+	$im->add(eml_load 't/data/0001.patch') or BAIL_OUT;
+	$im->done;
 	$t0 = Time::HiRes::time();
 	ok(@res = $mic->idle_data(11), "IDLE succeeds on $ng after HUP");
 	is(grep(/\A\* [0-9] EXISTS\b/, @res), 1, 'got EXISTS message');
@@ -356,7 +353,7 @@ EOF
 	my $ret = $mic->fetch_hash(2, 'RFC822');
 	is_deeply($ret, {},
 		'MSN FETCH on empty dummy will not trigger warnings, later');
-}); # each_inbox
+}; # for @ibx
 
 # message sequence numbers :<
 is($mic->Uid(0), 0, 'disable UID on '.ref($mic));
@@ -439,7 +436,6 @@ ok($mic->logout, 'logged out');
 }
 
 SKIP: {
-	use_ok 'PublicInbox::Watch';
 	use_ok 'PublicInbox::InboxIdle';
 	require_git('1.8.5', 1) or
 		skip('git 1.8.5+ needed for --urlmatch', 4);

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

* [PATCH 22/35] t/solver_git: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (20 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 21/35] t/imapd: create_inbox (minor) Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 23/35] t/cgi: create_inbox Eric Wong
                   ` (12 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

This saves us a dozen or so milliseconds.
---
 t/solver_git.t | 88 ++++++++++++++++++++++++--------------------------
 1 file changed, 42 insertions(+), 46 deletions(-)

diff --git a/t/solver_git.t b/t/solver_git.t
index 3ae7259a..99ffb9e3 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -1,10 +1,10 @@
+#!perl -w
 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
-use Cwd qw(abs_path);
+use v5.10.1;
 use PublicInbox::TestCommon;
+use Cwd qw(abs_path);
 require_git(2.6);
 use PublicInbox::Spawn qw(popen_rd);
 require_mods(qw(DBD::SQLite Search::Xapian Plack::Util));
@@ -17,31 +17,21 @@ $git_dir = abs_path($git_dir);
 
 use_ok "PublicInbox::$_" for (qw(Inbox V2Writable Git SolverGit WWW));
 
-my ($inboxdir, $for_destroy) = tmpdir();
-my $opts = {
-	inboxdir => $inboxdir,
-	name => 'test-v2writable',
-	version => 2,
-	-primary_address => 'test@example.com',
-};
-my $ibx = PublicInbox::Inbox->new($opts);
-my $im = PublicInbox::V2Writable->new($ibx, 1);
-$im->{parallel} = 0;
-
-my $deliver_patch = sub ($) {
-	$im->add(eml_load($_[0]));
-	$im->done;
+my ($tmpdir, $for_destroy) = tmpdir();
+my $ibx = create_inbox 'v2', version => 2,
+			indexlevel => 'medium', sub {
+	my ($im) = @_;
+	$im->add(eml_load 't/solve/0001-simple-mod.patch') or BAIL_OUT;
+	$im->add(eml_load 't/solve/0002-rename-with-modifications.patch') or
+		BAIL_OUT;
 };
-
-$deliver_patch->('t/solve/0001-simple-mod.patch');
 my $v1_0_0_tag = 'cb7c42b1e15577ed2215356a2bf925aef59cdd8d';
 my $v1_0_0_tag_short = substr($v1_0_0_tag, 0, 16);
-
 my $git = PublicInbox::Git->new($git_dir);
 $ibx->{-repo_objs} = [ $git ];
 my $res;
 my $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
-open my $log, '+>>', "$inboxdir/solve.log" or die "open: $!";
+open my $log, '+>>', "$tmpdir/solve.log" or die "open: $!";
 my $psgi_env = { 'psgi.errors' => \*STDERR, 'psgi.url_scheme' => 'http',
 		'HTTP_HOST' => 'example.com' };
 $solver->solve($psgi_env, $log, '69df7d5', {});
@@ -57,12 +47,6 @@ is(ref($wt_git->cat_file($res->[1])), 'SCALAR', 'wt cat-file works');
 is_deeply([$expect, 'blob', 4405],
 	  [$wt_git->check($res->[1])], 'wt check works');
 
-if (0) { # TODO: check this?
-	seek($log, 0, 0);
-	my $z = do { local $/; <$log> };
-	diag $z;
-}
-
 my $oid = $expect;
 for my $i (1..2) {
 	my $more;
@@ -87,7 +71,6 @@ $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
 $solver->solve($psgi_env, $log, $git_v2_20_1_tag, {});
 is($res, undef, 'no error on a tag not in our repo');
 
-$deliver_patch->('t/solve/0002-rename-with-modifications.patch');
 $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
 $solver->solve($psgi_env, $log, '0a92431', {});
 ok($res, 'resolved without hints');
@@ -108,9 +91,9 @@ my @psgi = qw(HTTP::Request::Common Plack::Test URI::Escape Plack::Builder);
 SKIP: {
 	require_mods(@psgi, 7 + scalar(@psgi));
 	use_ok($_) for @psgi;
-	my $binfoo = "$inboxdir/binfoo.git";
-	require PublicInbox::Import;
-	PublicInbox::Import::init_bare($binfoo);
+	my $binfoo = "$ibx->{inboxdir}/binfoo.git";
+	my $l = "$ibx->{inboxdir}/inbox.lock";
+	-f $l or BAIL_OUT "BUG: $l missing: $!";
 	require_ok 'PublicInbox::ViewVCS';
 	my $big_size = do {
 		no warnings 'once';
@@ -118,27 +101,40 @@ SKIP: {
 	};
 	my %bin = (big => $big_size, small => 1);
 	my %oid; # (small|big) => OID
-	my $cmd = [ qw(git hash-object -w --stdin) ];
-	my $env = { GIT_DIR => $binfoo };
-	while (my ($label, $size) = each %bin) {
-		pipe(my ($rin, $win)) or die;
-		my $rout = popen_rd($cmd , $env, { 0 => $rin });
-		$rin = undef;
-		print { $win } ("\0" x $size) or die;
-		close $win or die;
-		chomp($oid{$label} = <$rout>);
-		close $rout or die "$?";
+	my $lk = bless { lock_path => $l }, 'PublicInbox::Lock';
+	my $acq = $lk->lock_for_scope;
+	my $stamp = "$binfoo/stamp";
+	if (open my $fh, '<', $stamp) {
+		%oid = map { chomp; split(/=/, $_) } (<$fh>);
+	} else {
+		PublicInbox::Import::init_bare($binfoo);
+		my $cmd = [ qw(git hash-object -w --stdin) ];
+		my $env = { GIT_DIR => $binfoo };
+		open my $fh, '>', "$stamp.$$" or BAIL_OUT;
+		while (my ($label, $size) = each %bin) {
+			pipe(my ($rin, $win)) or BAIL_OUT;
+			my $rout = popen_rd($cmd , $env, { 0 => $rin });
+			$rin = undef;
+			print { $win } ("\0" x $size) or BAIL_OUT;
+			close $win or BAIL_OUT;
+			chomp(my $x = <$rout>);
+			close $rout or BAIL_OUT "$?";
+			print $fh "$label=$x\n" or BAIL_OUT;
+			$oid{$label} = $x;
+		}
+		close $fh or BAIL_OUT;
+		rename("$stamp.$$", $stamp) or BAIL_OUT;
 	}
-
+	undef $acq;
 	# ensure the PSGI frontend (ViewVCS) works:
 	my $name = $ibx->{name};
 	my $cfgpfx = "publicinbox.$name";
-	my $cfgpath = "$inboxdir/httpd-config";
+	my $cfgpath = "$tmpdir/httpd-config";
 	open my $cfgfh, '>', $cfgpath or die;
 	print $cfgfh <<EOF or die;
 [publicinbox "$name"]
-	address = $ibx->{address};
-	inboxdir = $inboxdir
+	address = $ibx->{-primary_address}
+	inboxdir = $ibx->{inboxdir}
 	coderepo = public-inbox
 	coderepo = binfoo
 	url = http://example.com/$name
@@ -193,7 +189,7 @@ EOF
 		require_mods(qw(Plack::Test::ExternalServer), 7);
 		my $env = { PI_CONFIG => $cfgpath };
 		my $sock = tcp_server() or die;
-		my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err);
+		my ($out, $err) = map { "$tmpdir/std$_.log" } qw(out err);
 		my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
 		my $td = start_script($cmd, $env, { 3 => $sock });
 		my ($h, $p) = tcp_host_port($sock);

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

* [PATCH 23/35] t/cgi: create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (21 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 22/35] t/solver_git: use create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 24/35] t/edit: switch to create_inbox Eric Wong
                   ` (11 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

This only saves a few ms but is nicer to look at.
---
 t/cgi.t | 84 +++++++++++++++++++++++----------------------------------
 1 file changed, 34 insertions(+), 50 deletions(-)

diff --git a/t/cgi.t b/t/cgi.t
index 567c2ee0..95e6e735 100644
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -5,61 +5,34 @@ use strict;
 use v5.10.1;
 use PublicInbox::TestCommon;
 use IO::Uncompress::Gunzip qw(gunzip);
-require_mods(qw(Plack::Handler::CGI Plack::Util));
-require PublicInbox::Eml;
-require PublicInbox::Import;
-require PublicInbox::Inbox;
-require PublicInbox::InboxWritable;
-require PublicInbox::Config;
+use PublicInbox::Eml;
+use IO::Handle;
 my ($tmpdir, $for_destroy) = tmpdir();
-my $home = "$tmpdir/pi-home";
-my $pi_home = "$home/.public-inbox";
-my $pi_config = "$pi_home/config";
-my $maindir = "$tmpdir/main.git";
-my $addr = 'test-public@example.com';
-PublicInbox::Import::init_bare($maindir);
-{
-	mkdir($home, 0755) or BAIL_OUT $!;
-	mkdir($pi_home, 0755) or BAIL_OUT $!;
-	open my $fh, '>>', $pi_config or BAIL_OUT $!;
-	print $fh <<EOF or BAIL_OUT $!;
-[publicinbox "test"]
-	address = $addr
-	inboxdir = $maindir
-	indexlevel = basic
-EOF
-	close $fh or BAIL_OUT $!;
-}
-
-my $cfg = PublicInbox::Config->new($pi_config);
-my $ibx = $cfg->lookup_name('test');
-my $im = PublicInbox::InboxWritable->new($ibx)->importer(0);
-
-{
-	local $ENV{HOME} = $home;
-
-	# inject some messages:
-	my $mime = PublicInbox::Eml->new(<<EOF);
+require_mods(qw(Plack::Handler::CGI Plack::Util));
+my $slashy_mid = 'slashy/asdf@example.com';
+my $ibx = create_inbox 'test', tmpdir => "$tmpdir/test", sub {
+	my ($im, $ibx) = @_;
+	mkdir "$ibx->{inboxdir}/home", 0755 or BAIL_OUT;
+	mkdir "$ibx->{inboxdir}/home/.public-inbox", 0755 or BAIL_OUT;
+	my $eml = PublicInbox::Eml->new(<<EOF);
 From: Me <me\@example.com>
 To: You <you\@example.com>
-Cc: $addr
+Cc: $ibx->{-primary_address}
 Message-Id: <blah\@example.com>
 Subject: hihi
 Date: Thu, 01 Jan 1970 00:00:00 +0000
 
 zzzzzz
 EOF
-	ok($im->add($mime), 'added initial message');
-
-	$mime->header_set('Message-ID', '<toobig@example.com>');
-	$mime->body_set("z\n" x 1024);
-	ok($im->add($mime), 'added big message');
+	$im->add($eml) or BAIL_OUT;
+	$eml->header_set('Message-ID', '<toobig@example.com>');
+	$eml->body_set("z\n" x 1024);
+	$im->add($eml) or BAIL_OUT;
 
-	# deliver a reply, too
-	$mime = PublicInbox::Eml->new(<<EOF);
+	$eml = PublicInbox::Eml->new(<<EOF);
 From: You <you\@example.com>
 To: Me <me\@example.com>
-Cc: $addr
+Cc: $ibx->{-primary_address}
 In-Reply-To: <blah\@example.com>
 Message-Id: <blahblah\@example.com>
 Subject: Re: hihi
@@ -70,22 +43,31 @@ Me wrote:
 
 what?
 EOF
-	ok($im->add($mime), 'added reply');
-
-	my $slashy_mid = 'slashy/asdf@example.com';
-	my $slashy = PublicInbox::Eml->new(<<EOF);
+	$im->add($eml) or BAIL_OUT;
+	$eml = PublicInbox::Eml->new(<<EOF);
 From: You <you\@example.com>
 To: Me <me\@example.com>
-Cc: $addr
+Cc: $ibx->{-primary_address}
 Message-Id: <$slashy_mid>
 Subject: Re: hihi
 Date: Thu, 01 Jan 1970 00:00:01 +0000
 
 slashy
 EOF
-	ok($im->add($slashy), 'added slash');
-	$im->done;
+	$im->add($eml) or BAIL_OUT;
+}; # create_inbox
 
+my $home = "$ibx->{inboxdir}/home";
+open my $cfgfh, '>>', "$home/.public-inbox/config" or BAIL_OUT $!;
+print $cfgfh <<EOF or BAIL_OUT $!;
+[publicinbox "test"]
+	address = $ibx->{-primary_address}
+	inboxdir = $ibx->{inboxdir}
+EOF
+$cfgfh->flush or BAIL_OUT $!;
+
+{
+	local $ENV{HOME} = $home;
 	my $res = cgi_run("/test/slashy/asdf\@example.com/raw");
 	like($res->{body}, qr/Message-Id: <\Q$slashy_mid\E>/,
 		"slashy mid raw hit");
@@ -98,6 +80,8 @@ SKIP: {
 	my $res = cgi_run($path);
 	like($res->{head}, qr/^Status: 501 /, "search not-yet-enabled");
 	my $cmd = ['-index', $ibx->{inboxdir}, '--max-size=2k'];
+	print $cfgfh "\tindexlevel = basic\n" or BAIL_OUT $!;
+	$cfgfh->flush or BAIL_OUT $!;
 	my $opt = { 2 => \(my $err) };
 	my $indexed = run_script($cmd, undef, $opt);
 	if ($indexed) {

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

* [PATCH 24/35] t/edit: switch to create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (22 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 23/35] t/cgi: create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 25/35] t/inbox_idle: " Eric Wong
                   ` (10 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Hardly any time reduction, but code gets more compact.
---
 t/edit.t | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/t/edit.t b/t/edit.t
index 0d57e629..e6e0f9cf 100644
--- a/t/edit.t
+++ b/t/edit.t
@@ -1,35 +1,26 @@
+#!perl -w
 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # edit frontend behavior test (t/replace.t for backend)
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
-require_git(2.6);
-require PublicInbox::Inbox;
-require PublicInbox::InboxWritable;
-require PublicInbox::Config;
 use PublicInbox::MID qw(mid_clean);
+require_git(2.6);
 
 require_mods('DBD::SQLite');
 my ($tmpdir, $for_destroy) = tmpdir();
 my $inboxdir = "$tmpdir/v2";
-my $ibx = PublicInbox::Inbox->new({
-	inboxdir => $inboxdir,
-	name => 'test-v2edit',
-	version => 2,
-	-primary_address => 'test@example.com',
-	indexlevel => 'basic',
-});
-$ibx = PublicInbox::InboxWritable->new($ibx, {nproc=>1});
+my $file = 't/data/0001.patch';
+my $eml = eml_load($file);
+my $mid = mid_clean($eml->header('Message-ID'));
+my $ibx = create_inbox 'v2edit', indexlevel => 'basic', version => 2,
+			tmpdir => $inboxdir, sub {
+	my ($im, $ibx) = @_;
+	$im->add($eml) or BAIL_OUT;
+};
 my $cfgfile = "$tmpdir/config";
 local $ENV{PI_CONFIG} = $cfgfile;
-my $im = $ibx->importer(0);
-my $file = 't/data/0001.patch';
-my $mime = eml_load($file);
-my $mid = mid_clean($mime->header('Message-Id'));
-ok($im->add($mime), 'add message to be edited');
-$im->done;
 my ($in, $out, $err, $cmd, $cur, $t);
 my $git = PublicInbox::Git->new("$ibx->{inboxdir}/git/0.git");
 my $opt = { 0 => \$in, 1 => \$out, 2 => \$err };
@@ -155,7 +146,8 @@ $t = '--raw and mbox escaping'; {
 $t = 'reuse Message-ID'; {
 	my @warn;
 	local $SIG{__WARN__} = sub { push @warn, @_ };
-	ok($im->add($mime), "$t and re-add");
+	my $im = $ibx->importer(0);
+	ok($im->add($eml), "$t and re-add");
 	$im->done;
 	like($warn[0], qr/reused for mismatched content/, "$t got warning");
 }

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

* [PATCH 25/35] t/inbox_idle: switch to create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (23 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 24/35] t/edit: switch to create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 26/35] t/lei_xsearch: use create_inbox Eric Wong
                   ` (9 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Surprising to me, this is actually significantly faster
even though we're starting off with an empty inbox due
to -no_fsync being the default.
---
 t/inbox_idle.t | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/t/inbox_idle.t b/t/inbox_idle.t
index 27facfe9..c9df73a1 100644
--- a/t/inbox_idle.t
+++ b/t/inbox_idle.t
@@ -1,41 +1,35 @@
 #!perl -w
 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use Test::More;
+use strict;
+use v5.10.1;
 use PublicInbox::TestCommon;
 use PublicInbox::Config;
 require_git 2.6;
 require_mods(qw(DBD::SQLite));
 require PublicInbox::SearchIdx;
 use_ok 'PublicInbox::InboxIdle';
-use PublicInbox::InboxWritable;
 my ($tmpdir, $for_destroy) = tmpdir();
 
 for my $V (1, 2) {
 	my $inboxdir = "$tmpdir/$V";
-	mkdir $inboxdir or BAIL_OUT("mkdir: $!");
-	my %opt = (
-		inboxdir => $inboxdir,
-		name => 'inbox-idle',
-		version => $V,
-		-primary_address => 'test@example.com',
-		indexlevel => 'basic',
-	);
-	my $ibx = PublicInbox::Inbox->new({ %opt });
-	$ibx = PublicInbox::InboxWritable->new($ibx);
-	my $obj = InboxIdleTestObj->new;
-	$ibx->init_inbox(0);
-	my $im = $ibx->importer(0);
-	if ($V == 1) {
+	my $ibx = create_inbox "idle$V", tmpdir => $inboxdir, version => $V,
+				indexlevel => 'basic', -no_gc => 1, sub {
+		my ($im, $ibx) = @_; # capture
+		$im->done;
+		$ibx->init_inbox(0);
+		$_[0] = undef;
+		return if $V != 1;
 		my $sidx = PublicInbox::SearchIdx->new($ibx, 1);
 		$sidx->idx_acquire;
 		$sidx->set_metadata_once;
 		$sidx->idx_release; # allow watching on lockfile
-	}
+	};
+	my $obj = InboxIdleTestObj->new;
 	my $pi_cfg = PublicInbox::Config->new(\<<EOF);
 publicinbox.inbox-idle.inboxdir=$inboxdir
 publicinbox.inbox-idle.indexlevel=basic
-publicinbox.inbox-idle.address=test\@example.com
+publicinbox.inbox-idle.address=$ibx->{-primary_address}
 EOF
 	my $ident = 'whatever';
 	$pi_cfg->each_inbox(sub { shift->subscribe_unlock($ident, $obj) });
@@ -45,6 +39,7 @@ EOF
 		skip('inotify or kqueue missing', 1) unless $ii->{sock};
 		ok(fileno($ii->{sock}) >= 0, 'fileno() gave valid FD');
 	}
+	my $im = $ibx->importer(0);
 	ok($im->add(eml_load('t/utf8.eml')), "$V added");
 	$im->done;
 	PublicInbox::SearchIdx->new($ibx)->index_sync if $V == 1;

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

* [PATCH 26/35] t/lei_xsearch: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (24 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 25/35] t/inbox_idle: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 27/35] t/indexlevels-mirror: " Eric Wong
                   ` (8 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

This ends up being significantly faster when confined
to a slow TMPDIR.
---
 t/lei_xsearch.t | 27 ++++++---------------------
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/t/lei_xsearch.t b/t/lei_xsearch.t
index a1ab3ec8..f626c790 100644
--- a/t/lei_xsearch.t
+++ b/t/lei_xsearch.t
@@ -6,7 +6,6 @@ use v5.10.1;
 use List::Util qw(shuffle max);
 use PublicInbox::TestCommon;
 use PublicInbox::Eml;
-use PublicInbox::InboxWritable;
 require_mods(qw(DBD::SQLite Search::Xapian));
 require PublicInbox::ExtSearchIdx;
 require_git 2.6;
@@ -73,26 +72,12 @@ is($lxs->over, undef, '->over fails');
 
 {
 	$lxs = PublicInbox::LeiXSearch->new;
-	my $v2ibx = PublicInbox::InboxWritable->new({
-		inboxdir => "$home/v2full",
-		name => 'v2full',
-		version => 2,
-		indexlevel => 'full',
-		-primary_address => 'v2full@example.com',
-	}, {});
-	my $im = $v2ibx->importer(0);
-	$im->add(eml_load('t/plack-qp.eml'));
-	$im->done;
-	my $v1ibx = PublicInbox::InboxWritable->new({
-		inboxdir => "$home/v1medium",
-		name => 'v1medium',
-		version => 1,
-		indexlevel => 'medium',
-		-primary_address => 'v1medium@example.com',
-	}, {});
-	$im = $v1ibx->importer(0);
-	$im->add(eml_load('t/utf8.eml'));
-	$im->done;
+	my $v2ibx = create_inbox 'v2full', version => 2, sub {
+		$_[0]->add(eml_load('t/plack-qp.eml'));
+	};
+	my $v1ibx = create_inbox 'v1medium', indexlevel => 'medium', sub {
+		$_[0]->add(eml_load('t/utf8.eml'));
+	};
 	$lxs->prepare_external($v1ibx);
 	$lxs->prepare_external($v2ibx);
 	for my $loc ($lxs->locals) {

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

* [PATCH 27/35] t/indexlevels-mirror: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (25 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 26/35] t/lei_xsearch: use create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 28/35] t/multi-mid: " Eric Wong
                   ` (7 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

This saves hundreds of milliseconds and reduces LoC.
---
 t/indexlevels-mirror.t | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/t/indexlevels-mirror.t b/t/indexlevels-mirror.t
index 53826aef..bd140cc4 100644
--- a/t/indexlevels-mirror.t
+++ b/t/indexlevels-mirror.t
@@ -1,13 +1,12 @@
+#!perl -w
 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
+use PublicInbox::TestCommon;
 use PublicInbox::Eml;
 use PublicInbox::Inbox;
-use PublicInbox::InboxWritable;
 require PublicInbox::Admin;
-use PublicInbox::TestCommon;
 my $PI_TEST_VERSION = $ENV{PI_TEST_VERSION} || 2;
 require_git('2.6') if $PI_TEST_VERSION == 2;
 require_mods(qw(DBD::SQLite));
@@ -26,18 +25,13 @@ my $import_index_incremental = sub {
 	my $err = '';
 	my $this = "pi-$v-$level-indexlevels";
 	my ($tmpdir, $for_destroy) = tmpdir();
+	my $ibx = create_inbox "testbox$v", indexlevel => $level,
+				version => $v, tmpdir => "$tmpdir/v$v", sub {
+		$mime->header_set('Message-ID', '<m@1>');
+		$_[0]->add($mime) or BAIL_OUT;
+	};
+	my $im = $ibx->importer(0);
 	local $ENV{PI_CONFIG} = "$tmpdir/config";
-	my $ibx = PublicInbox::Inbox->new({
-		inboxdir => "$tmpdir/testbox",
-		name => $this,
-		version => $v,
-		-primary_address => 'test@example.com',
-		indexlevel => $level,
-	});
-	my $im = PublicInbox::InboxWritable->new($ibx, {nproc=>1})->importer(0);
-	$mime->header_set('Message-ID', '<m@1>');
-	ok($im->add($mime), 'first message added');
-	$im->done;
 
 	# index master (required for v1)
 	my @cmd = (qw(-index -j0), $ibx->{inboxdir}, "-L$level");

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

* [PATCH 28/35] t/multi-mid: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (26 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 27/35] t/indexlevels-mirror: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 29/35] t/psgi_search: " Eric Wong
                   ` (6 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

---
 t/multi-mid.t | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/t/multi-mid.t b/t/multi-mid.t
index e9c3dd8c..4a5b8c32 100644
--- a/t/multi-mid.t
+++ b/t/multi-mid.t
@@ -4,11 +4,10 @@ use strict;
 use Test::More;
 use PublicInbox::Eml;
 use PublicInbox::TestCommon;
-use PublicInbox::InboxWritable;
 require_git(2.6);
 require_mods(qw(DBD::SQLite));
 require PublicInbox::SearchIdx;
-my $delay = $ENV{TEST_DELAY_CONVERT};
+my $delay = $ENV{TEST_DELAY_CONVERT} // '';
 
 my $addr = 'test@example.com';
 my $bad = PublicInbox::Eml->new(<<EOF);
@@ -28,34 +27,25 @@ Subject: good
 
 EOF
 
+my $nr = 0;
 for my $order ([$bad, $good], [$good, $bad]) {
-	my $before;
 	my ($tmpdir, $for_destroy) = tmpdir();
-	my $ibx = PublicInbox::InboxWritable->new({
-		inboxdir => "$tmpdir/v1",
-		name => 'test-v1',
-		indexlevel => 'basic',
-		-primary_address => $addr,
-	}, my $creat_opt = {});
-	my @old;
-	if ('setup v1 inbox') {
-		my $im = $ibx->importer(0);
-		for (@$order) {
-			ok($im->add($_), 'added '.$_->header('Subject'));
+	my $ibx = create_inbox "test$delay.$nr", indexlevel => 'basic', sub {
+		my ($im) = @_;
+		for my $eml (@$order) {
+			$im->add($eml) or BAIL_OUT;
 			sleep($delay) if $delay;
 		}
-		$im->done;
-		my $s = PublicInbox::SearchIdx->new($ibx, 1);
-		$s->index_sync;
-		$before = [ $ibx->mm->minmax ];
-		@old = ($ibx->over->get_art(1), $ibx->over->get_art(2));
-		$ibx->cleanup;
-	}
+	};
+	++$nr;
+	my $before = [ $ibx->mm->minmax ];
+	my @old = ($ibx->over->get_art(1), $ibx->over->get_art(2));
+	$ibx->cleanup;
 	my $rdr = { 1 => \(my $out = ''), 2 => \(my $err = '') };
 	my $cmd = [ '-convert', $ibx->{inboxdir}, "$tmpdir/v2" ];
 	my $env = { PI_DIR => "$tmpdir/.public-inbox" };
 	ok(run_script($cmd, $env, $rdr), 'convert to v2');
-	$err =~ s!\AW: $tmpdir/v1 not configured[^\n]+\n!!s;
+	$err =~ s!\AW: \Q$ibx->{inboxdir}\E not configured[^\n]+\n!!s;
 	is($err, '', 'no errors or warnings from -convert');
 	$ibx->{version} = 2;
 	$ibx->{inboxdir} = "$tmpdir/v2";

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

* [PATCH 29/35] t/psgi_search: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (27 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 28/35] t/multi-mid: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 30/35] t/miscsearch: " Eric Wong
                   ` (5 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

---
 t/psgi_search.t | 37 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

diff --git a/t/psgi_search.t b/t/psgi_search.t
index 9facdf3d..d59e439b 100644
--- a/t/psgi_search.t
+++ b/t/psgi_search.t
@@ -1,15 +1,14 @@
+#!perl -w
 # Copyright (C) 2017-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
+use PublicInbox::TestCommon;
 use IO::Uncompress::Gunzip qw(gunzip);
 use PublicInbox::Eml;
 use PublicInbox::Config;
 use PublicInbox::Inbox;
-use PublicInbox::InboxWritable;
 use bytes (); # only for bytes::length
-use PublicInbox::TestCommon;
 my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
 		URI::Escape Plack::Builder);
 require_mods(@mods);
@@ -19,58 +18,46 @@ use_ok 'PublicInbox::SearchIdx';
 my ($tmpdir, $for_destroy) = tmpdir();
 local $ENV{TZ} = 'UTC';
 
-my $ibx = PublicInbox::Inbox->new({
-	inboxdir => $tmpdir,
-	address => 'git@vger.kernel.org',
-	name => 'test',
-});
-$ibx = PublicInbox::InboxWritable->new($ibx);
-$ibx->init_inbox(1);
-my $im = $ibx->importer(0);
 my $digits = '10010260936330';
 my $ua = 'Pine.LNX.4.10';
 my $mid = "$ua.$digits.2460-100000\@penguin.transmeta.com";
-
-# n.b. these headers are not properly RFC2047-encoded
-my $mime = PublicInbox::Eml->new(<<EOF);
+my $ibx = create_inbox 'git', indexlevel => 'full', tmpdir => "$tmpdir/1", sub {
+	my ($im) = @_;
+	# n.b. these headers are not properly RFC2047-encoded
+	$im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
 Subject: test Ævar
 Message-ID: <$mid>
 From: Ævar Arnfjörð Bjarmason <avarab\@example>
 To: git\@vger.kernel.org
 
 EOF
-$im->add($mime);
 
-$im->add(PublicInbox::Eml->new(<<""));
+	$im->add(PublicInbox::Eml->new(<<"")) or BAIL_OUT;
 Message-ID: <reply\@asdf>
 From: replier <r\@example.com>
 In-Reply-To: <$mid>
 Subject: mismatch
 
-$mime = PublicInbox::Eml->new(<<'EOF');
+	$im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
 Subject:
 Message-ID: <blank-subject@example.com>
 From: blank subject <blank-subject@example.com>
 To: git@vger.kernel.org
 
 EOF
-$im->add($mime);
 
-$mime = PublicInbox::Eml->new(<<'EOF');
+	$im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
 Message-ID: <no-subject-at-all@example.com>
 From: no subject at all <no-subject-at-all@example.com>
 To: git@vger.kernel.org
 
 EOF
-$im->add($mime);
-
-$im->done;
-PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
+};
 
 my $cfgpfx = "publicinbox.test";
 my $cfg = PublicInbox::Config->new(\<<EOF);
 $cfgpfx.address=git\@vger.kernel.org
-$cfgpfx.inboxdir=$tmpdir
+$cfgpfx.inboxdir=$ibx->{inboxdir}
 EOF
 my $www = PublicInbox::WWW->new($cfg);
 test_psgi(sub { $www->call(@_) }, sub {

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

* [PATCH 30/35] t/miscsearch: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (28 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 29/35] t/psgi_search: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 31/35] t/nntpd-tls: " Eric Wong
                   ` (4 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

---
 t/miscsearch.t | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/t/miscsearch.t b/t/miscsearch.t
index 413579fb..307812a4 100644
--- a/t/miscsearch.t
+++ b/t/miscsearch.t
@@ -2,34 +2,26 @@
 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
+use v5.10.1;
 use Test::More;
 use PublicInbox::TestCommon;
-use PublicInbox::InboxWritable;
 require_mods(qw(Search::Xapian DBD::SQLite));
 use_ok 'PublicInbox::MiscSearch';
 use_ok 'PublicInbox::MiscIdx';
 
 my ($tmp, $for_destroy) = tmpdir();
 my $eidx = { xpfx => "$tmp/eidx", -no_fsync => 1 }; # mock ExtSearchIdx
-{
-	mkdir "$tmp/v1" or BAIL_OUT "mkdir $!";
-	open my $fh, '>', "$tmp/v1/description" or BAIL_OUT "open: $!";
+my $v1 = create_inbox 'hope', address => [ 'nope@example.com' ],
+			indexlevel => 'basic', -no_gc => 1, sub {
+	my ($im, $ibx) = @_;
+	open my $fh, '>', "$ibx->{inboxdir}/description" or BAIL_OUT "open: $!";
 	print $fh "Everything sucks this year\n" or BAIL_OUT "print $!";
 	close $fh or BAIL_OUT "close $!";
-}
-{
-	my $v1 = PublicInbox::InboxWritable->new({
-		inboxdir => "$tmp/v1",
-		name => 'hope',
-		address => [ 'nope@example.com' ],
-		indexlevel => 'basic',
-		version => 1,
-	});
-	$v1->init_inbox;
-	my $mi = PublicInbox::MiscIdx->new($eidx);
-	$mi->index_ibx($v1);
-	$mi->commit_txn;
-}
+};
+my $midx = PublicInbox::MiscIdx->new($eidx);
+$midx->index_ibx($v1);
+$midx->commit_txn;
+undef $v1;
 
 my $ms = PublicInbox::MiscSearch->new("$tmp/eidx/misc");
 my $mset = $ms->mset('"everything sucks today"');

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

* [PATCH 31/35] t/nntpd-tls: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (29 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 30/35] t/miscsearch: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 32/35] t/nntpd: " Eric Wong
                   ` (3 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Another 100ms or so saved.
---
 t/nntpd-tls.t | 52 ++++++++++++++++-----------------------------------
 1 file changed, 16 insertions(+), 36 deletions(-)

diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t
index 8dab4ca8..2c09d34e 100644
--- a/t/nntpd-tls.t
+++ b/t/nntpd-tls.t
@@ -1,10 +1,10 @@
+#!perl -w
 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
-use Socket qw(SOCK_STREAM IPPROTO_TCP SOL_SOCKET);
+use v5.10.1;
 use PublicInbox::TestCommon;
+use Socket qw(SOCK_STREAM IPPROTO_TCP SOL_SOCKET);
 # IO::Poll and Net::NNTP are part of the standard library, but
 # distros may split them off...
 require_mods(qw(DBD::SQLite IO::Socket::SSL Net::NNTP IO::Poll));
@@ -20,9 +20,6 @@ unless (-r $key && -r $cert) {
 
 use_ok 'PublicInbox::TLS';
 use_ok 'IO::Socket::SSL';
-require PublicInbox::InboxWritable;
-require PublicInbox::Eml;
-require PublicInbox::SearchIdx;
 our $need_zlib;
 eval { require Compress::Raw::Zlib } or
 	$need_zlib = 'Compress::Raw::Zlib missing';
@@ -31,45 +28,28 @@ require_git('2.6') if $version >= 2;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
-my $inboxdir = "$tmpdir";
-my $pi_config = "$tmpdir/pi_config";
 my $group = 'test-nntpd-tls';
 my $addr = $group . '@example.com';
 my $starttls = tcp_server();
 my $nntps = tcp_server();
-my $ibx = PublicInbox::Inbox->new({
-	inboxdir => $inboxdir,
-	name => 'nntpd-tls',
-	version => $version,
-	-primary_address => $addr,
-	indexlevel => 'basic',
-});
-$ibx = PublicInbox::InboxWritable->new($ibx, {nproc=>1});
-$ibx->init_inbox(0);
-{
-	open my $fh, '>', $pi_config or die "open: $!\n";
-	print $fh <<EOF
+my $pi_config;
+my $ibx = create_inbox "v$version", version => $version, indexlevel => 'basic',
+			sub {
+	my ($im, $ibx) = @_;
+	$pi_config = "$ibx->{inboxdir}/pi_config";
+	open my $fh, '>', $pi_config or BAIL_OUT "open: $!";
+	print $fh <<EOF or BAIL_OUT;
 [publicinbox "nntpd-tls"]
-	inboxdir = $inboxdir
+	inboxdir = $ibx->{inboxdir}
 	address = $addr
 	indexlevel = basic
 	newsgroup = $group
 EOF
-	;
-	close $fh or die "close: $!\n";
-}
-
-{
-	my $im = $ibx->importer(0);
-	my $mime = eml_load 't/data/0001.patch';
-	ok($im->add($mime), 'message added');
-	$im->done;
-	if ($version == 1) {
-		my $s = PublicInbox::SearchIdx->new($ibx, 1);
-		$s->index_sync;
-	}
-}
-
+	close $fh or BAIL_OUT "close: $!";
+	$im->add(eml_load 't/data/0001.patch') or BAIL_OUT;
+};
+$pi_config //= "$ibx->{inboxdir}/pi_config";
+undef $ibx;
 my $nntps_addr = tcp_host_port($nntps);
 my $starttls_addr = tcp_host_port($starttls);
 my $env = { PI_CONFIG => $pi_config };

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

* [PATCH 32/35] t/nntpd: use create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (30 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 31/35] t/nntpd-tls: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 33/35] t/thread-index-gap: create_inbox Eric Wong
                   ` (2 subsequent siblings)
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

---
 t/nntpd.t | 102 +++++++++++++++++++++++++-----------------------------
 1 file changed, 48 insertions(+), 54 deletions(-)

diff --git a/t/nntpd.t b/t/nntpd.t
index 16a2ab76..7db371dd 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -1,12 +1,11 @@
+#!perl -w
 # Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::TestCommon;
 use PublicInbox::Spawn qw(which);
 require_mods(qw(DBD::SQLite));
-require PublicInbox::InboxWritable;
 use PublicInbox::Eml;
 use Socket qw(IPPROTO_TCP TCP_NODELAY);
 use Net::NNTP;
@@ -26,49 +25,14 @@ my ($tmpdir, $for_destroy) = tmpdir();
 my $home = "$tmpdir/pi-home";
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
-my $inboxdir = "$tmpdir/main";
-my $otherdir = "$tmpdir/other";
+my $inboxdir = "$tmpdir/inbox";
 my $group = 'test-nntpd';
 my $addr = $group . '@example.com';
-
-my %opts;
 my $sock = tcp_server();
 my $host_port = tcp_host_port($sock);
 my $td;
-my $len;
-
-my $ibx = {
-	inboxdir => $inboxdir,
-	name => $group,
-	version => $version,
-	-primary_address => $addr,
-	indexlevel => 'basic',
-};
-$ibx = PublicInbox::Inbox->new($ibx);
-{
-	local $ENV{HOME} = $home;
-	my @cmd = ('-init', $group, $inboxdir, 'http://example.com/abc', $addr,
-		"-V$version", '-Lbasic', '--newsgroup', $group);
-	ok(run_script(\@cmd), "init $group");
 
-	@cmd = ('-init', 'xyz', $otherdir, 'http://example.com/xyz',
-		'e@example.com', "-V$version", qw(-Lbasic --newsgroup x.y.z));
-	ok(run_script(\@cmd), 'init xyz');
-	is(xsys([qw(git config -f), "$home/.public-inbox/config",
-		qw(publicinboxmda.spamcheck none)]), 0, 'disable spamcheck');
-
-	open(my $fh, '<', 't/utf8.eml') or BAIL_OUT("open t/utf8.eml: $!");
-	my $env = { ORIGINAL_RECIPIENT => 'e@example.com' };
-	run_script([qw(-mda --no-precheck)], $env, { 0 => $fh }) or
-		BAIL_OUT('-mda delivery');
-
-	my $len;
-	$ibx = PublicInbox::InboxWritable->new($ibx);
-	my $im = $ibx->importer(0);
-
-	# ensure successful message delivery
-	{
-		my $mime = PublicInbox::Eml->new(<<EOF);
+my $eml = PublicInbox::Eml->new(<<EOF);
 To: =?utf-8?Q?El=C3=A9anor?= <you\@example.com>
 From: =?utf-8?Q?El=C3=A9anor?= <me\@example.com>
 Cc: $addr
@@ -81,21 +45,49 @@ References: <ref	tab	squeezed>
 
 This is a test message for El\xc3\xa9anor
 EOF
-		my $list_id = $addr;
-		$list_id =~ s/@/./;
-		$mime->header_set('List-Id', "<$list_id>");
-		my $str = $mime->as_string;
-		$str =~ s/(?<!\r)\n/\r\n/sg;
-		$len = length($str);
-		undef $str;
-		$im->add($mime);
-		$im->done;
-		if ($version == 1) {
-			ok(run_script(['-index', $ibx->{inboxdir}]),
-				'indexed v1');
-		}
-	}
+my $list_id = $addr;
+$list_id =~ s/@/./;
+$eml->header_set('List-Id', "<$list_id>");
+my $str = $eml->as_string;
+$str =~ s/(?<!\r)\n/\r\n/sg;
+my $len = length($str);
+undef $str;
+
+my $ibx = create_inbox "v$version", version => $version, indexlevel => 'basic',
+			tmpdir => $inboxdir, sub {
+	my ($im, $ibx) = @_;
+	$im->add($eml) or BAIL_OUT;
+};
+undef $eml;
+my $other = create_inbox "other$version", version => $version,
+		indexlevel => 'basic', sub {
+	my ($im) = @_;
+	$im->add(eml_load 't/utf8.eml') or BAIL_OUT;
+};
 
+local $ENV{HOME} = $home;
+mkdir $home or BAIL_OUT $!;
+mkdir "$home/.public-inbox" or BAIL_OUT $!;
+open my $cfgfh, '>', "$home/.public-inbox/config" or BAIL_OUT $!;
+print $cfgfh <<EOF or BAIL_OUT;
+[publicinbox "$group"]
+	inboxdir = $inboxdir
+	url = http://example.com/abc
+	address = $addr
+	indexlevel = basic
+	newsgroup = $group
+[publicinbox "xyz"]
+	inboxdir = $other->{inboxdir}
+	url = http://example.com/xyz
+	address = e\@example.com
+	indexlevel = basic
+	newsgroup = x.y.z
+[publicinboxMda]
+	spamcheck = none
+EOF
+close $cfgfh or BAIL_OUT;
+
+{
 	my $cmd = [ '-nntpd', '-W0', "--stdout=$out", "--stderr=$err" ];
 	$td = start_script($cmd, undef, { 3 => $sock });
 	my $n = Net::NNTP->new($host_port);
@@ -258,6 +250,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 
 		my $long_hdr = 'for-leafnode-'.('y'x200).'@example.com';
 		$for_leafnode->header_set('Message-ID', "<$long_hdr>");
+		my $im = $ibx->importer(0);
 		$im->add($for_leafnode);
 		$im->done;
 		if ($version == 1) {
@@ -354,6 +347,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 		my $ex = eml_load('t/data/0001.patch');
 		is($n->article($ex->header('Message-ID')), undef,
 			'article did not exist');
+		my $im = $ibx->importer(0);
 		$im->add($ex);
 		$im->done;
 		{

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

* [PATCH 33/35] t/thread-index-gap: create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (31 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 32/35] t/nntpd: " Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 34/35] t/altid_v2: create_inbox Eric Wong
  2021-03-15 11:58 ` [PATCH 35/35] t/*: disable fsync on tests were create_inbox isn't worth it Eric Wong
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Yes, this loses some randomness w.r.t. shuffle, but I
think it's "good enough" and buys us ~100ms speedup on
an SSD TMPDIR.
---
 t/thread-index-gap.t | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/t/thread-index-gap.t b/t/thread-index-gap.t
index 125c5cbd..d3cb6204 100644
--- a/t/thread-index-gap.t
+++ b/t/thread-index-gap.t
@@ -3,10 +3,8 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
-use Test::More;
 use PublicInbox::TestCommon;
 use PublicInbox::Eml;
-use PublicInbox::InboxWritable;
 use PublicInbox::Config;
 use List::Util qw(shuffle);
 require_mods(qw(DBD::SQLite));
@@ -31,26 +29,26 @@ References: <20201202045540.31248-1-j@example.com>
 EOF
 
 my ($home, $for_destroy) = tmpdir();
-local $ENV{HOME} = $home;
 for my $msgs (['orig', reverse @msgs], ['shuffle', shuffle(@msgs)]) {
 	my $desc = shift @$msgs;
 	my $n = "index-cap-$desc";
-	run_script([qw(-init -L basic -V2), $n, "$home/$n",
-		"http://example.com/$n", "$n\@example.com"]) or
-		BAIL_OUT 'init';
-	my $ibx = PublicInbox::Config->new->lookup_name($n);
-	my $im = PublicInbox::InboxWritable->new($ibx)->importer(0);
-	for my $m (@$msgs) {
-		$im->add(PublicInbox::Eml->new("$m\nFrom: x\@example.com\n\n"));
-	}
-	$im->done;
+	# yes, the shuffle case gets memoized by create_inbox, oh well
+	my $ibx = create_inbox $desc, version => 2, indexlevel => 'full',
+				tmpdir => "$home/$desc", sub {
+		my ($im) = @_;
+		for my $m (@$msgs) {
+			my $x = "$m\nFrom: x\@example.com\n\n";
+			$im->add(PublicInbox::Eml->new(\$x));
+		}
+	};
 	my $over = $ibx->over;
 	my $dbh = $over->dbh;
 	my $tid = $dbh->selectall_arrayref('SELECT DISTINCT(tid) FROM over');
 	is(scalar(@$tid), 1, "only one thread initially ($desc)");
 	$over->dbh_close;
+	my $env = { HOME => $home };
 	run_script([qw(-index --no-fsync --reindex --rethread),
-			$ibx->{inboxdir}]) or BAIL_OUT 'rethread';
+			$ibx->{inboxdir}], $env) or BAIL_OUT 'rethread';
 	$tid = $dbh->selectall_arrayref('SELECT DISTINCT(tid) FROM over');
 	is(scalar(@$tid), 1, "only one thread after rethread ($desc)");
 }

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

* [PATCH 34/35] t/altid_v2: create_inbox
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (32 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 33/35] t/thread-index-gap: create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  2021-03-15 11:58 ` [PATCH 35/35] t/*: disable fsync on tests were create_inbox isn't worth it Eric Wong
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Another 100ms saved
---
 t/altid_v2.t | 48 +++++++++++++++++-------------------------------
 1 file changed, 17 insertions(+), 31 deletions(-)

diff --git a/t/altid_v2.t b/t/altid_v2.t
index c6295b2f..493982a1 100644
--- a/t/altid_v2.t
+++ b/t/altid_v2.t
@@ -1,37 +1,23 @@
+#!perl -w
 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
-use PublicInbox::Eml;
+use v5.10.1;
 use PublicInbox::TestCommon;
+use PublicInbox::Eml;
+use PublicInbox::Msgmap;
 require_git(2.6);
 require_mods(qw(DBD::SQLite Search::Xapian));
-use_ok 'PublicInbox::V2Writable';
-use_ok 'PublicInbox::Inbox';
-my ($tmpdir, $for_destroy) = tmpdir();
-my $inboxdir = "$tmpdir/inbox";
-my $full = "$tmpdir/inbox/another-nntp.sqlite3";
-my $altid = [ 'serial:gmane:file=another-nntp.sqlite3' ];
-
-{
-	ok(mkdir($inboxdir), 'created repo for msgmap');
-	my $mm = PublicInbox::Msgmap->new_file($full, 1);
-	is($mm->mid_set(1234, 'a@example.com'), 1, 'mid_set once OK');
+my $another = 'another-nntp.sqlite3';
+my $altid = [ "serial:gmane:file=$another" ];
+my $ibx = create_inbox 'v2', version => 2, indexlevel => 'medium',
+			altid => $altid, sub {
+	my ($im, $ibx) = @_;
+	my $mm = PublicInbox::Msgmap->new_file("$ibx->{inboxdir}/$another", 1);
+	$mm->mid_set(1234, 'a@example.com') == 1 or BAIL_OUT 'mid_set once';
 	ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
 	ok(0 == $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
-}
-
-my $ibx = {
-	inboxdir => $inboxdir,
-	name => 'test-v2writable',
-	version => 2,
-	-primary_address => 'test@example.com',
-	altid => $altid,
-};
-$ibx = PublicInbox::Inbox->new($ibx);
-my $v2w = PublicInbox::V2Writable->new($ibx, 1);
-$v2w->add(PublicInbox::Eml->new(<<'EOF'));
+	$im->add(PublicInbox::Eml->new(<<'EOF')) or BAIL_OUT;
 From: a@example.com
 To: b@example.com
 Subject: boo!
@@ -39,9 +25,11 @@ Message-ID: <a@example.com>
 
 hello world gmane:666
 EOF
-$v2w->done;
-
-my $mset = $ibx->search->reopen->mset('gmane:1234');
+};
+my $mm = PublicInbox::Msgmap->new_file("$ibx->{inboxdir}/$another", 1);
+ok(0 == $mm->mid_set(1234, 'a@example.com'), 'mid_set not idempotent');
+ok(0 ==  $mm->mid_set(1, 'a@example.com'), 'mid_set fails with dup MID');
+my $mset = $ibx->search->mset('gmane:1234');
 my $msgs = $ibx->search->mset_to_smsg($ibx, $mset);
 $msgs = [ map { $_->{mid} } @$msgs ];
 is_deeply($msgs, ['a@example.com'], 'got one match');
@@ -49,5 +37,3 @@ $mset = $ibx->search->mset('gmane:666');
 is($mset->size, 0, 'body did NOT match');
 
 done_testing();
-
-1;

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

* [PATCH 35/35] t/*: disable fsync on tests were create_inbox isn't worth it
  2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
                   ` (33 preceding siblings ...)
  2021-03-15 11:58 ` [PATCH 34/35] t/altid_v2: create_inbox Eric Wong
@ 2021-03-15 11:58 ` Eric Wong
  34 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 11:58 UTC (permalink / raw)
  To: meta

Using create_inbox doesn't seem worth the trouble, here, at the
moment, but disabling fsync(2) gives a noticeable speedup on
my system even with an SSD.
---
 t/extsearch.t             | 2 ++
 t/purge.t                 | 1 +
 t/replace.t               | 1 +
 t/v1reindex.t             | 1 +
 t/v2-add-remove-add.t     | 1 +
 t/v2mirror.t              | 1 +
 t/v2reindex.t             | 1 +
 t/v2writable.t            | 1 +
 t/watch_filter_rubylang.t | 2 ++
 t/watch_maildir_v2.t      | 1 +
 10 files changed, 12 insertions(+)

diff --git a/t/extsearch.t b/t/extsearch.t
index d199fc7b..ae889ac6 100644
--- a/t/extsearch.t
+++ b/t/extsearch.t
@@ -236,6 +236,7 @@ if ('inject w/o indexing') {
 
 if ('reindex catches missed messages') {
 	my $v2ibx = $cfg->lookup_name('v2test');
+	$v2ibx->{-no_fsync} = 1;
 	my $im = PublicInbox::InboxWritable->new($v2ibx)->importer(0);
 	my $cmt_a = $v2ibx->mm->last_commit_xap($schema_version, 0);
 	my $eml = eml_load('t/data/0001.patch');
@@ -296,6 +297,7 @@ if ('reindex catches missed messages') {
 if ('reindex catches content bifurcation') {
 	use PublicInbox::MID qw(mids);
 	my $v2ibx = $cfg->lookup_name('v2test');
+	$v2ibx->{-no_fsync} = 1;
 	my $im = PublicInbox::InboxWritable->new($v2ibx)->importer(0);
 	my $eml = eml_load('t/data/message_embed.eml');
 	my $cmt_a = $v2ibx->mm->last_commit_xap($schema_version, 0);
diff --git a/t/purge.t b/t/purge.t
index f4281c13..a33cd329 100644
--- a/t/purge.t
+++ b/t/purge.t
@@ -16,6 +16,7 @@ my $ibx = PublicInbox::Inbox->new({
 	inboxdir => $inboxdir,
 	name => 'test-v2purge',
 	version => 2,
+	-no_fsync => 1,
 	-primary_address => 'test@example.com',
 	indexlevel => 'basic',
 });
diff --git a/t/replace.t b/t/replace.t
index 51bdb964..626cbe9b 100644
--- a/t/replace.t
+++ b/t/replace.t
@@ -20,6 +20,7 @@ sub test_replace ($$$) {
 		inboxdir => "$tmpdir/testbox",
 		name => $this,
 		version => $v,
+		-no_fsync => 1,
 		-primary_address => 'test@example.com',
 		indexlevel => $level,
 	});
diff --git a/t/v1reindex.t b/t/v1reindex.t
index 36cefda5..f593b323 100644
--- a/t/v1reindex.t
+++ b/t/v1reindex.t
@@ -18,6 +18,7 @@ my $ibx_config = {
 	name => 'test-v1reindex',
 	-primary_address => 'test@example.com',
 	indexlevel => 'full',
+	-no_fsync => 1,
 };
 my $mime = PublicInbox::Eml->new(<<'EOF');
 From: a@example.com
diff --git a/t/v2-add-remove-add.t b/t/v2-add-remove-add.t
index b325e521..579cdcb6 100644
--- a/t/v2-add-remove-add.t
+++ b/t/v2-add-remove-add.t
@@ -13,6 +13,7 @@ my $ibx = {
 	inboxdir => "$inboxdir/v2",
 	name => 'test-v2writable',
 	version => 2,
+	-no_fsync => 1,
 	-primary_address => 'test@example.com',
 };
 $ibx = PublicInbox::Inbox->new($ibx);
diff --git a/t/v2mirror.t b/t/v2mirror.t
index 12e3fcd0..012e5bd2 100644
--- a/t/v2mirror.t
+++ b/t/v2mirror.t
@@ -36,6 +36,7 @@ my $cfg = PublicInbox::Config->new($pi_config);
 my $ibx = $cfg->lookup('test@example.com');
 ok($ibx, 'inbox found');
 $ibx->{version} = 2;
+$ibx->{-no_fsync} = 1;
 my $v2w = PublicInbox::V2Writable->new($ibx, 1);
 ok $v2w, 'v2w loaded';
 $v2w->{parallel} = 0;
diff --git a/t/v2reindex.t b/t/v2reindex.t
index a931225c..1145e31b 100644
--- a/t/v2reindex.t
+++ b/t/v2reindex.t
@@ -18,6 +18,7 @@ my $ibx_config = {
 	version => 2,
 	-primary_address => 'test@example.com',
 	indexlevel => 'full',
+	-no_fsync => 1,
 };
 my $agpl = do {
 	open my $fh, '<', 'COPYING' or die "can't open COPYING: $!";
diff --git a/t/v2writable.t b/t/v2writable.t
index f0fa8a79..d9e7b980 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -17,6 +17,7 @@ my $ibx = {
 	inboxdir => $inboxdir,
 	name => 'test-v2writable',
 	version => 2,
+	-no_fsync => 1,
 	-primary_address => 'test@example.com',
 };
 $ibx = PublicInbox::Inbox->new($ibx);
diff --git a/t/watch_filter_rubylang.t b/t/watch_filter_rubylang.t
index 29a9f793..5deb2082 100644
--- a/t/watch_filter_rubylang.t
+++ b/t/watch_filter_rubylang.t
@@ -74,6 +74,7 @@ publicinboxwatch.watchspam=maildir:$spamdir
 EOF
 	my $cfg = PublicInbox::Config->new(\$orig);
 	my $ibx = $cfg->lookup_name($v);
+	$ibx->{-no_fsync} = 1;
 	ok($ibx, 'found inbox by name');
 
 	my $w = PublicInbox::Watch->new($cfg);
@@ -103,6 +104,7 @@ EOF
 
 	$cfg = PublicInbox::Config->new(\$orig);
 	$ibx = $cfg->lookup_name($v);
+	$ibx->{-no_fsync} = 1;
 	is($ibx->search->reopen->mset('b:spam')->size, 0, 'spam removed');
 
 	is_deeply([], \@warn, 'no warnings');
diff --git a/t/watch_maildir_v2.t b/t/watch_maildir_v2.t
index 195e238b..7b46232b 100644
--- a/t/watch_maildir_v2.t
+++ b/t/watch_maildir_v2.t
@@ -47,6 +47,7 @@ EOF
 my $cfg = PublicInbox::Config->new(\$orig);
 my $ibx = $cfg->lookup_name('test');
 ok($ibx, 'found inbox by name');
+$ibx->{-no_fsync} = 1;
 
 PublicInbox::Watch->new($cfg)->scan('full');
 my $total = scalar @{$ibx->over->recent};

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

* [SQUASH] [PATCH 08/35] t/admin: switch to create_inbox
  2021-03-15 11:57 ` [PATCH 08/35] t/admin: switch to create_inbox Eric Wong
@ 2021-03-15 19:51   ` Eric Wong
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Wong @ 2021-03-15 19:51 UTC (permalink / raw)
  To: meta

quiet down "git gc" warnings on empty inboxes
---
 t/admin.t | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/admin.t b/t/admin.t
index 4402c5ae..8d09bfc1 100644
--- a/t/admin.t
+++ b/t/admin.t
@@ -6,7 +6,7 @@ use v5.10.1;
 use PublicInbox::TestCommon;
 use PublicInbox::Import;
 use_ok 'PublicInbox::Admin';
-my $v1 = create_inbox 'v1', sub {};
+my $v1 = create_inbox 'v1', -no_gc => 1, sub {};
 my ($tmpdir, $for_destroy) = tmpdir();
 my $git_dir = $v1->{inboxdir};
 my ($res, $err, $v);
@@ -14,7 +14,8 @@ my $v2ibx;
 SKIP: {
 	require_mods(qw(DBD::SQLite), 5);
 	require_git(2.6, 1) or skip 5, 'git too old';
-	$v2ibx = create_inbox 'v2', indexlevel => 'basic', version => 2, sub {
+	$v2ibx = create_inbox 'v2', indexlevel => 'basic', version => 2,
+				-no_gc => 1, sub {
 		my ($v2w, $ibx) = @_;
 		$v2w->idx_init;
 		$v2w->importer;

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

end of thread, other threads:[~2021-03-15 19:51 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong
2021-03-15 11:57 ` [PATCH 01/35] test_common: add create_inbox helper sub Eric Wong
2021-03-15 11:57 ` [PATCH 02/35] t/lei_xsearch: use create_inbox Eric Wong
2021-03-15 11:57 ` [PATCH 03/35] test_common: minor simplifications to setup_public_inboxes Eric Wong
2021-03-15 11:57 ` [PATCH 04/35] t/imapd-tls: switch to create_inbox Eric Wong
2021-03-15 11:57 ` [PATCH 05/35] t/www_altid: use create_inbox Eric Wong
2021-03-15 11:57 ` [PATCH 06/35] t/xcpdb-reshard: " Eric Wong
2021-03-15 11:57 ` [PATCH 07/35] t/v2dupindex: create_inbox Eric Wong
2021-03-15 11:57 ` [PATCH 08/35] t/admin: switch to create_inbox Eric Wong
2021-03-15 19:51   ` [SQUASH] " Eric Wong
2021-03-15 11:58 ` [PATCH 09/35] t/html_index: remove now-worthless test Eric Wong
2021-03-15 11:58 ` [PATCH 10/35] t/plack: use create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 11/35] t/psgi_attach: convert to create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 12/35] t/httpd: " Eric Wong
2021-03-15 11:58 ` [PATCH 13/35] t/convert-compact: create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 14/35] t/altid: use create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 15/35] t/psgi_mount: switch to create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 16/35] t/feed: " Eric Wong
2021-03-15 11:58 ` [PATCH 17/35] t/psgi_bad_mids: use create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 18/35] t/psgi_multipart_not: " Eric Wong
2021-03-15 11:58 ` [PATCH 19/35] t/psgi_scan_all: create_inbox lots saved Eric Wong
2021-03-15 11:58 ` [PATCH 20/35] t/psgi_v2: create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 21/35] t/imapd: create_inbox (minor) Eric Wong
2021-03-15 11:58 ` [PATCH 22/35] t/solver_git: use create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 23/35] t/cgi: create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 24/35] t/edit: switch to create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 25/35] t/inbox_idle: " Eric Wong
2021-03-15 11:58 ` [PATCH 26/35] t/lei_xsearch: use create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 27/35] t/indexlevels-mirror: " Eric Wong
2021-03-15 11:58 ` [PATCH 28/35] t/multi-mid: " Eric Wong
2021-03-15 11:58 ` [PATCH 29/35] t/psgi_search: " Eric Wong
2021-03-15 11:58 ` [PATCH 30/35] t/miscsearch: " Eric Wong
2021-03-15 11:58 ` [PATCH 31/35] t/nntpd-tls: " Eric Wong
2021-03-15 11:58 ` [PATCH 32/35] t/nntpd: " Eric Wong
2021-03-15 11:58 ` [PATCH 33/35] t/thread-index-gap: create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 34/35] t/altid_v2: create_inbox Eric Wong
2021-03-15 11:58 ` [PATCH 35/35] t/*: disable fsync on tests were create_inbox isn't worth it 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).