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