]> Sergey Matveev's repositories - public-inbox.git/blob - xt/mem-msgview.t
make Plack optional for non-WWW and non-httpd users
[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 use strict;
5 use IO::Handle; # ->flush
6 use Fcntl qw(SEEK_SET);
7 use PublicInbox::TestCommon;
8 use PublicInbox::Tmpfile;
9 use Test::More;
10 my @mods = qw(DBD::SQLite BSD::Resource PublicInbox::WWW);
11 require_mods(@mods);
12 use_ok($_) for @mods;
13 my $lines = $ENV{NR_LINES} // 100000;
14 my ($tmpdir, $for_destroy) = tmpdir();
15 my $inboxname = 'big';
16 my $inboxdir = "$tmpdir/big";
17 local $ENV{PI_CONFIG} = "$tmpdir/cfg";
18 my $mid = 'test@example.com';
19
20 { # setup
21         open my $fh, '>', "$tmpdir/cfg" or die;
22         print $fh <<EOF or die;
23 [publicinboxmda]
24         spamcheck = none
25 EOF
26         close $fh or die;
27
28         my $addr = 'n@example.com';
29         ok(run_script([qw(-init -V2 --indexlevel=basic), $inboxname, $inboxdir,
30                         "http://example.com/$inboxname", $addr]),
31                 'inbox initialized');
32
33         $fh = tmpfile('big.eml', undef, my $append = 1) or die;
34         printf($fh <<'EOF', $addr, $mid) or die;
35 From: Dr. X <x@example.com>
36 To: Nikki <%s>
37 Date: Tue, 3 May 1988 00:00:00 +0000
38 Subject: todo
39 Message-ID: <%s>
40
41 EOF
42         for (0..$lines) { print $fh 'x' x 72, "\n" or die }
43         $fh->flush or die;
44         sysseek($fh, 0, SEEK_SET) or die;
45         my $env = { ORIGINAL_RECIPIENT => $addr };
46         my $err = '';
47         my $opt = { 0 => $fh, 2 => \$err, run_mode => 0 };
48         ok(run_script([qw(-mda --no-precheck)], $env, $opt),
49                 '1st message delivered');
50
51         # resend the message with same mid but different content
52         print $fh "mindcrime\n" or die;
53         $fh->flush or die;
54         sysseek($fh, 0, SEEK_SET) or die;
55         ok(run_script([qw(-mda --no-precheck)], $env, $opt),
56                 '2nd message delivered');
57 }
58
59 my $www = PublicInbox::WWW->new;
60 my $env = {
61         PATH_INFO => "/$inboxname/$mid/",
62         REQUEST_URI => "/$inboxname/$mid/",
63         SCRIPT_NAME => '',
64         QUERY_STRING => '',
65         REQUEST_METHOD => 'GET',
66         HTTP_HOST => 'example.com',
67         'psgi.errors' => \*STDERR,
68         'psgi.url_scheme' => 'http',
69 };
70 my $ru_before = BSD::Resource::getrusage();
71 my $res = $www->call($env);
72 my $body = $res->[2];
73 while (defined(my $x = $body->getline)) {
74 }
75 $body->close;
76 my $ru_after = BSD::Resource::getrusage();
77 my $diff = $ru_after->maxrss - $ru_before->maxrss;
78 diag "before: ${\$ru_before->maxrss} => ${\$ru_after->maxrss} diff=$diff kB";
79 done_testing();