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;
9 use File::Path qw(mkpath);
10 use IO::Handle (); # autoflush
12 use Cwd qw(getcwd abs_path);
14 my $many_root = $ENV{TEST_MANY_ROOT} or
15 plan skip_all => 'TEST_MANY_ROOT not defined';
18 -d $many_root or BAIL_OUT "$many_root: $!";
19 $many_root = abs_path($many_root);
20 $many_root =~ m!\A\Q$cwd\E/! and BAIL_OUT "$many_root must not be in $cwd";
22 require_mods(qw(DBD::SQLite Search::Xapian));
23 use_ok 'PublicInbox::V2Writable';
24 my $nr_inbox = $ENV{NR_INBOX} // 10;
25 my $nproc = $ENV{NPROC} || PublicInbox::IPC::detect_nproc() || 2;
26 my $indexlevel = $ENV{TEST_INDEXLEVEL} // 'basic';
27 diag "NR_INBOX=$nr_inbox NPROC=$nproc TEST_INDEXLEVEL=$indexlevel";
28 diag "TEST_MANY_ROOT=$many_root";
29 my $level_cfg = $indexlevel eq 'full' ? '' : "\tindexlevel = $indexlevel\n";
30 my $pfx = "$many_root/$nr_inbox-$indexlevel";
32 open my $cfg_fh, '>>', "$pfx/config" or BAIL_OUT $!;
33 $cfg_fh->autoflush(1);
34 my $v2_init_add = sub {
36 my $ibx = PublicInbox::Inbox->new({
37 inboxdir => "$pfx/test-$i",
39 newsgroup => "inbox.comp.test.foo.test-$i",
40 address => [ "test-$i\@example.com" ],
41 url => [ "//example.com/test-$i" ],
45 $ibx->{indexlevel} = $indexlevel if $level_cfg ne '';
47 [publicinbox "$ibx->{name}"]
48 address = $ibx->{-primary_address}
49 url = $ibx->{url}->[0]
50 newsgroup = $ibx->{newsgroup}
51 inboxdir = $ibx->{inboxdir}
54 print $cfg_fh $entry or die $!;
55 my $v2w = PublicInbox::V2Writable->new($ibx, { nproc => 0 });
57 $v2w->add(PublicInbox::Eml->new(<<EOM));
58 Date: Sat, 02 Oct 2010 00:00:00 +0000
59 From: Lorelei <l\@example.com>
60 To: test-$i\@example.com
61 Message-ID: <20101002-000000-$i\@example.com>
62 Subject: hello world $i
70 for my $i (1..$nproc) {
72 pipe($r, $w) or BAIL_OUT $!;
73 my $pid = fork // BAIL_OUT "fork: $!";
76 while (my $i = <$r>) {
82 close $r or BAIL_OUT $!;
83 push @children, [ $w, $pid ];
87 for my $i (0..$nr_inbox) {
88 print { $children[$i % @children]->[0] } "$i\n" or BAIL_OUT $!;
91 for my $c (@children) {
92 close $c->[0] or BAIL_OUT "close $!";
95 for my $c (@children) {
96 my $pid = waitpid($c->[1], 0);
97 is($?, 0, ++$i.' exited ok');
99 ok(close($cfg_fh), 'config written');