2 # Copyright (C) 2020 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 my ($tmpdir, $for_destroy) = tmpdir();
17 my $inboxname = 'big';
18 my $inboxdir = "$tmpdir/big";
19 local $ENV{PI_CONFIG} = "$tmpdir/cfg";
20 my $mid = 'test@example.com';
23 open my $fh, '>', "$tmpdir/cfg" or die;
24 print $fh <<EOF or die;
30 my $addr = 'n@example.com';
31 ok(run_script([qw(-init -V2 --indexlevel=basic), $inboxname, $inboxdir,
32 "http://example.com/$inboxname", $addr]),
35 $fh = tmpfile('big.eml', undef, my $append = 1) or die;
36 my $hdr = sprintf(<<'EOF', $addr, $mid);
37 From: Dr. X <x@example.com>
39 Date: Tue, 3 May 1988 00:00:00 +0000
43 Content-Type: multipart/mixed; boundary="FOO"
44 Content-Disposition: inline
47 Content-Type: text/plain; charset=utf-8
48 Content-Disposition: inline
51 print $fh $hdr or die;
52 for (0..$lines) { print $fh 'x' x 72, "\n" or die }
53 print $fh <<EOF or die;
56 Content-Type: text/plain; charset=utf-8
57 Content-Disposition: inline
60 for (0..$lines) { print $fh 'x' x 72, "\n" or die }
61 print $fh "\n--FOO--\n" or die;
63 sysseek($fh, 0, SEEK_SET) or die;
64 my $env = { ORIGINAL_RECIPIENT => $addr };
66 my $opt = { 0 => $fh, 2 => \$err, run_mode => 0 };
67 ok(run_script([qw(-mda --no-precheck)], $env, $opt),
71 my $www = PublicInbox::WWW->new;
73 PATH_INFO => "/$inboxname/$mid/",
74 REQUEST_URI => "/$inboxname/$mid/",
77 REQUEST_METHOD => 'GET',
78 HTTP_HOST => 'example.com',
79 'psgi.errors' => \*STDERR,
80 'psgi.url_scheme' => 'http',
82 my $ru_before = BSD::Resource::getrusage();
83 my $res = $www->call($env);
85 while (defined(my $x = $body->getline)) {
88 my $ru_after = BSD::Resource::getrusage();
89 my $diff = $ru_after->maxrss - $ru_before->maxrss;
90 diag "before: ${\$ru_before->maxrss} => ${\$ru_after->maxrss} diff=$diff kB";