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>
4 # Note: this may be altered as-needed to demonstrate improvements.
5 # See history in git for this file.
7 use IO::Handle; # ->flush
8 use Fcntl qw(SEEK_SET);
9 use PublicInbox::TestCommon;
10 use PublicInbox::Tmpfile;
12 my @mods = qw(DBD::SQLite BSD::Resource PublicInbox::WWW);
15 my $lines = $ENV{NR_LINES} // 50000;
16 diag "NR_LINES=$lines";
17 my ($tmpdir, $for_destroy) = tmpdir();
18 my $inboxname = 'big';
19 my $inboxdir = "$tmpdir/big";
20 local $ENV{PI_CONFIG} = "$tmpdir/cfg";
21 my $mid = 'test@example.com';
24 open my $fh, '>', "$tmpdir/cfg" or die;
25 print $fh <<EOF or die;
31 my $addr = 'n@example.com';
32 ok(run_script([qw(-init -V2 --indexlevel=basic), $inboxname, $inboxdir,
33 "http://example.com/$inboxname", $addr]),
36 $fh = tmpfile('big.eml', undef, my $append = 1) or die;
37 my $hdr = sprintf(<<'EOF', $addr, $mid);
38 From: Dr. X <x@example.com>
40 Date: Tue, 3 May 1988 00:00:00 +0000
44 Content-Type: multipart/mixed; boundary="FOO"
45 Content-Disposition: inline
48 Content-Type: text/plain; charset=utf-8
49 Content-Disposition: inline
52 print $fh $hdr or die;
53 for (0..$lines) { print $fh 'x' x 72, "\n" or die }
54 print $fh <<EOF or die;
57 Content-Type: text/plain; charset=utf-8
58 Content-Disposition: inline
61 for (0..$lines) { print $fh 'x' x 72, "\n" or die }
62 print $fh "\n--FOO--\n" or die;
64 sysseek($fh, 0, SEEK_SET) or die;
65 my $env = { ORIGINAL_RECIPIENT => $addr };
67 my $opt = { 0 => $fh, 2 => \$err, run_mode => 0 };
68 ok(run_script([qw(-mda --no-precheck)], $env, $opt),
72 my $www = PublicInbox::WWW->new;
74 PATH_INFO => "/$inboxname/$mid/",
75 REQUEST_URI => "/$inboxname/$mid/",
78 REQUEST_METHOD => 'GET',
79 HTTP_HOST => 'example.com',
80 'psgi.errors' => \*STDERR,
81 'psgi.url_scheme' => 'http',
83 my $ru_before = BSD::Resource::getrusage();
84 my $res = $www->call($env);
86 while (defined(my $x = $body->getline)) {
89 my $ru_after = BSD::Resource::getrusage();
90 my $diff = $ru_after->maxrss - $ru_before->maxrss;
91 diag "before: ${\$ru_before->maxrss} => ${\$ru_after->maxrss} diff=$diff kB";