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