2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use IO::Handle; # ->flush
6 use Fcntl qw(SEEK_SET);
7 use PublicInbox::TestCommon;
8 use PublicInbox::Tmpfile;
11 my @mods = qw(DBD::SQLite BSD::Resource);
14 my $lines = $ENV{NR_LINES} // 100000;
15 my ($tmpdir, $for_destroy) = tmpdir();
16 my $inboxname = 'big';
17 my $inboxdir = "$tmpdir/big";
18 local $ENV{PI_CONFIG} = "$tmpdir/cfg";
19 my $mid = 'test@example.com';
22 open my $fh, '>', "$tmpdir/cfg" or die;
23 print $fh <<EOF or die;
29 my $addr = 'n@example.com';
30 ok(run_script([qw(-init -V2 --indexlevel=basic), $inboxname, $inboxdir,
31 "http://example.com/$inboxname", $addr]),
34 $fh = tmpfile('big.eml', undef, my $append = 1) or die;
35 printf($fh <<'EOF', $addr, $mid) or die;
36 From: Dr. X <x@example.com>
38 Date: Tue, 3 May 1988 00:00:00 +0000
43 for (0..$lines) { print $fh 'x' x 72, "\n" or die }
45 sysseek($fh, 0, SEEK_SET) or die;
46 my $env = { ORIGINAL_RECIPIENT => $addr };
48 my $opt = { 0 => $fh, 2 => \$err, run_mode => 0 };
49 ok(run_script([qw(-mda --no-precheck)], $env, $opt),
50 '1st message delivered');
52 # resend the message with same mid but different content
53 print $fh "mindcrime\n" or die;
55 sysseek($fh, 0, SEEK_SET) or die;
56 ok(run_script([qw(-mda --no-precheck)], $env, $opt),
57 '2nd message delivered');
60 my $www = PublicInbox::WWW->new;
62 PATH_INFO => "/$inboxname/$mid/",
63 REQUEST_URI => "/$inboxname/$mid/",
66 REQUEST_METHOD => 'GET',
67 HTTP_HOST => 'example.com',
68 'psgi.errors' => \*STDERR,
69 'psgi.url_scheme' => 'http',
71 my $ru_before = BSD::Resource::getrusage();
72 my $res = $www->call($env);
74 while (defined(my $x = $body->getline)) {
77 my $ru_after = BSD::Resource::getrusage();
78 my $diff = $ru_after->maxrss - $ru_before->maxrss;
79 diag "before: ${\$ru_before->maxrss} => ${\$ru_after->maxrss} diff=$diff kB";