]> Sergey Matveev's repositories - public-inbox.git/blob - xt/eml_check_roundtrip.t
xt: remove eml_check_roundtrip
[public-inbox.git] / xt / eml_check_roundtrip.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 Test::More;
6 use PublicInbox::TestCommon;
7 use PublicInbox::Eml;
8 use PublicInbox::Inbox;
9 use List::Util qw(max);
10 use Benchmark qw(:all :hireswallclock);
11 use PublicInbox::Spawn qw(popen_rd);
12 use Carp ();
13 require_git(2.19); # for --unordered
14 my $inboxdir = $ENV{GIANT_INBOX_DIR};
15 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
16 my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'x' });
17 my $git = $ibx->git;
18 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects --unordered);
19 my $fh = $git->popen(@cat);
20 my $cat_cb = sub {
21         my ($bref, $oid, $type, $size, $check) = @_;
22         my $orig = $$bref;
23         my $copy = PublicInbox::Eml->new($bref)->as_string;
24         ++$check->[$orig eq $copy ? 0 : 1];
25 };
26
27 my $n = 0;
28 my $check = [ 0, 0 ]; # [ eql, neq ]
29 my $t = timeit(1, sub {
30         my ($blob, $type);
31         while (<$fh>) {
32                 ($blob, $type) = split / /;
33                 next if $type ne 'blob';
34                 $git->cat_async($blob, $cat_cb, $check);
35                 if ((++$n % 8192) == 0) {
36                         diag "n=$n eql=$check->[0] neq=$check->[1]";
37                 }
38         }
39         $git->cat_async_wait;
40 });
41 is($check->[0], $n, 'all messages round tripped');
42 is($check->[1], 0, 'no messages failed to round trip');
43 done_testing;