2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
8 use File::Path qw(mkpath);
9 use IO::Handle (); # autoflush
11 use Cwd qw(getcwd abs_path);
13 my $many_root = $ENV{TEST_MANY_ROOT} or
14 plan skip_all => 'TEST_MANY_ROOT not defined';
17 -d $many_root or BAIL_OUT "$many_root: $!";
18 $many_root = abs_path($many_root);
19 $many_root =~ m!\A\Q$cwd\E/! and BAIL_OUT "$many_root must not be in $cwd";
21 require_mods(qw(DBD::SQLite Search::Xapian));
22 use_ok 'PublicInbox::V2Writable';
23 my $nr_inbox = $ENV{NR_INBOX} // 10;
24 my $nproc = $ENV{NPROC} || PublicInbox::V2Writable::detect_nproc() || 2;
25 my $indexlevel = $ENV{TEST_INDEXLEVEL} // 'basic';
26 diag "NR_INBOX=$nr_inbox NPROC=$nproc TEST_INDEXLEVEL=$indexlevel";
27 diag "TEST_MANY_ROOT=$many_root";
28 my $level_cfg = $indexlevel eq 'full' ? '' : "\tindexlevel = $indexlevel\n";
29 my $pfx = "$many_root/$nr_inbox-$indexlevel";
31 open my $cfg_fh, '>>', "$pfx/config" or BAIL_OUT $!;
32 $cfg_fh->autoflush(1);
33 my $v2_init_add = sub {
35 my $ibx = PublicInbox::Inbox->new({
36 inboxdir => "$pfx/test-$i",
38 newsgroup => "inbox.comp.test.foo.test-$i",
39 address => [ "test-$i\@example.com" ],
40 url => [ "//example.com/test-$i" ],
43 $ibx->{indexlevel} = $indexlevel if $level_cfg ne '';
45 [publicinbox "$ibx->{name}"]
46 address = $ibx->{-primary_address}
47 url = $ibx->{url}->[0]
48 newsgroup = $ibx->{newsgroup}
49 inboxdir = $ibx->{inboxdir}
52 print $cfg_fh $entry or die $!;
53 my $v2w = PublicInbox::V2Writable->new($ibx, { nproc => 0 });
55 $v2w->add(PublicInbox::Eml->new(<<EOM));
56 Date: Sat, 02 Oct 2010 00:00:00 +0000
57 From: Lorelei <l\@example.com>
58 To: test-$i\@example.com
59 Message-ID: <20101002-000000-$i\@example.com>
60 Subject: hello world $i
68 for my $i (1..$nproc) {
70 pipe($r, $w) or BAIL_OUT $!;
74 while (my $i = <$r>) {
80 defined $pid or BAIL_OUT "fork: $!";
81 close $r or BAIL_OUT $!;
82 push @children, [ $w, $pid ];
86 for my $i (0..$nr_inbox) {
87 print { $children[$i % @children]->[0] } "$i\n" or BAIL_OUT $!;
90 for my $c (@children) {
91 close $c->[0] or BAIL_OUT "close $!";
94 for my $c (@children) {
95 my $pid = waitpid($c->[1], 0);
96 is($?, 0, ++$i.' exited ok');
98 ok(close($cfg_fh), 'config written');