]> Sergey Matveev's repositories - public-inbox.git/blob - xt/mem-msgview.t
dceb24b2386a322fa2ad0d806c2bc96f0c379fc5
[public-inbox.git] / xt / mem-msgview.t
1 #!perl -w
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.
6 use strict;
7 use IO::Handle; # ->flush
8 use Fcntl qw(SEEK_SET);
9 use PublicInbox::TestCommon;
10 use PublicInbox::Tmpfile;
11 use Test::More;
12 my @mods = qw(DBD::SQLite BSD::Resource PublicInbox::WWW);
13 require_mods(@mods);
14 use_ok($_) for @mods;
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';
22
23 { # setup
24         open my $fh, '>', "$tmpdir/cfg" or die;
25         print $fh <<EOF or die;
26 [publicinboxmda]
27         spamcheck = none
28 EOF
29         close $fh or die;
30
31         my $addr = 'n@example.com';
32         ok(run_script([qw(-init -V2 --indexlevel=basic), $inboxname, $inboxdir,
33                         "http://example.com/$inboxname", $addr]),
34                 'inbox initialized');
35
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>
39 To: Nikki <%s>
40 Date: Tue, 3 May 1988 00:00:00 +0000
41 Subject: todo
42 Message-ID: <%s>
43 MIME-Version: 1.0
44 Content-Type: multipart/mixed; boundary="FOO"
45 Content-Disposition: inline
46
47 --FOO
48 Content-Type: text/plain; charset=utf-8
49 Content-Disposition: inline
50
51 EOF
52         print $fh $hdr or die;
53         for (0..$lines) { print $fh 'x' x 72, "\n" or die }
54         print $fh <<EOF or die;
55
56 --FOO
57 Content-Type: text/plain; charset=utf-8
58 Content-Disposition: inline
59
60 EOF
61         for (0..$lines) { print $fh 'x' x 72, "\n" or die }
62         print $fh "\n--FOO--\n" or die;
63         $fh->flush or die;
64         sysseek($fh, 0, SEEK_SET) or die;
65         my $env = { ORIGINAL_RECIPIENT => $addr };
66         my $err = '';
67         my $opt = { 0 => $fh, 2 => \$err, run_mode => 0 };
68         ok(run_script([qw(-mda --no-precheck)], $env, $opt),
69                 'message delivered');
70 }
71
72 my $www = PublicInbox::WWW->new;
73 my $env = {
74         PATH_INFO => "/$inboxname/$mid/",
75         REQUEST_URI => "/$inboxname/$mid/",
76         SCRIPT_NAME => '',
77         QUERY_STRING => '',
78         REQUEST_METHOD => 'GET',
79         HTTP_HOST => 'example.com',
80         'psgi.errors' => \*STDERR,
81         'psgi.url_scheme' => 'http',
82 };
83 my $ru_before = BSD::Resource::getrusage();
84 my $res = $www->call($env);
85 my $body = $res->[2];
86 while (defined(my $x = $body->getline)) {
87 }
88 $body->close;
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";
92 done_testing();