]> Sergey Matveev's repositories - public-inbox.git/blob - xt/eml_check_limits.t
a6d010af0518f3f8866eebf0ee018bd336147f44
[public-inbox.git] / xt / eml_check_limits.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 use strict;
5 use v5.10.1;
6 use Test::More;
7 use PublicInbox::TestCommon;
8 use PublicInbox::Eml;
9 use PublicInbox::Inbox;
10 use List::Util qw(max);
11 use Benchmark qw(:all :hireswallclock);
12 use PublicInbox::Spawn qw(popen_rd);
13 use Carp ();
14 require_git(2.19); # for --unordered
15 require_mods(qw(BSD::Resource));
16 BSD::Resource->import(qw(getrusage));
17 my $cls = $ENV{TEST_CLASS};
18 if ($cls) {
19         diag "TEST_CLASS=$cls";
20         require_mods($cls);
21 }
22 $cls //= 'PublicInbox::Eml';
23 my $inboxdir = $ENV{GIANT_INBOX_DIR};
24 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
25 local $PublicInbox::Eml::mime_nesting_limit = 0x7fffffff;
26 local $PublicInbox::Eml::mime_parts_limit = 0x7fffffff;
27 local $PublicInbox::Eml::header_size_limit = 0x7fffffff;
28 my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'x' });
29 my $git = $ibx->git;
30 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects --unordered);
31 my $fh = $git->popen(@cat);
32 my ($m, $n);
33 my $max_nest = [ 0, '' ]; # [ bytes, blob oid ]
34 my $max_idx = [ 0, '' ];
35 my $max_parts = [ 0, '' ];
36 my $max_size = [ 0, '' ];
37 my $max_hdr = [ 0, '' ];
38 my $info = [ 0, '' ];
39 my $each_part_cb = sub {
40         my ($p) = @_;
41         my ($part, $depth, $idx) = @$p;
42         $max_nest = [ $depth, $info->[1] ] if $depth > $max_nest->[0];
43         my $max = max(split(/\./, $idx));
44         $max_idx = [ $max, $info->[1] ] if $max > $max_idx->[0];
45         ++$info->[0];
46 };
47
48 my ($bref, $oid, $size);
49 local $SIG{__WARN__} = sub { diag "$inboxdir $oid ", @_ };
50 my $cat_cb = sub {
51         ($bref, $oid, undef, $size) = @_;
52         ++$m;
53         $info = [ 0, $oid ];
54         my $eml = $cls->new($bref);
55         my $hdr_len = length($eml->header_obj->as_string);
56         $max_hdr = [ $hdr_len, $oid ] if $hdr_len > $max_hdr->[0];
57         $eml->each_part($each_part_cb, $info, 1);
58         $max_parts = $info if $info->[0] > $max_parts->[0];
59         $max_size = [ $size, $oid ] if $size > $max_size->[0];
60 };
61
62 my $t = timeit(1, sub {
63         my ($blob, $type);
64         while (<$fh>) {
65                 ($blob, $type) = split / /;
66                 next if $type ne 'blob';
67                 ++$n;
68                 $git->cat_async($blob, $cat_cb);
69         }
70         $git->async_wait_all;
71 });
72 is($m, $n, 'scanned all messages');
73 diag "$$ $inboxdir took ".timestr($t)." for $n <=> $m messages";
74 diag "$$ max_nest $max_nest->[0] @ $max_nest->[1]";
75 diag "$$ max_idx $max_idx->[0] @ $max_idx->[1]";
76 diag "$$ max_parts $max_parts->[0] @ $max_parts->[1]";
77 diag "$$ max_size $max_size->[0] @ $max_size->[1]";
78 diag "$$ max_hdr $max_hdr->[0] @ $max_hdr->[1]";
79 diag "$$ RSS ".getrusage()->maxrss. ' k';
80 done_testing;