MANIFEST | 1 +
xt/eml_check_roundtrip.t | 43 +++++++++++++++++++++++++++++++++++++++++++
diff --git a/MANIFEST b/MANIFEST
index b6a681e9b533e50971ae416a25ef7f9d94a6eb10..65fa87360ff579479e55bd683776dad606e4706a 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -385,6 +385,7 @@ t/xcpdb-reshard.t
xt/cmp-msgstr.t
xt/cmp-msgview.t
xt/eml_check_limits.t
+xt/eml_check_roundtrip.t
xt/git-http-backend.t
xt/git_async_cmp.t
xt/httpd-async-stream.t
diff --git a/xt/eml_check_roundtrip.t b/xt/eml_check_roundtrip.t
new file mode 100644
index 0000000000000000000000000000000000000000..9b216c53e6ae04b4e6491681a94c9054463b42a7
--- /dev/null
+++ b/xt/eml_check_roundtrip.t
@@ -0,0 +1,43 @@
+#!perl -w
+# Copyright (C) 2020 all contributors
+# License: AGPL-3.0+
+use strict;
+use Test::More;
+use PublicInbox::TestCommon;
+use PublicInbox::Eml;
+use PublicInbox::Inbox;
+use List::Util qw(max);
+use Benchmark qw(:all :hireswallclock);
+use PublicInbox::Spawn qw(popen_rd);
+use Carp ();
+require_git(2.19); # for --unordered
+my $inboxdir = $ENV{GIANT_INBOX_DIR};
+plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inboxdir;
+my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'x' });
+my $git = $ibx->git;
+my @cat = qw(cat-file --buffer --batch-check --batch-all-objects --unordered);
+my $fh = $git->popen(@cat);
+my $cat_cb = sub {
+ my ($bref, $oid, $type, $size, $check) = @_;
+ my $orig = $$bref;
+ my $copy = PublicInbox::Eml->new($bref)->as_string;
+ ++$check->[$orig eq $copy ? 0 : 1];
+};
+
+my $n = 0;
+my $check = [ 0, 0 ]; # [ eql, neq ]
+my $t = timeit(1, sub {
+ my ($blob, $type);
+ while (<$fh>) {
+ ($blob, $type) = split / /;
+ next if $type ne 'blob';
+ $git->cat_async($blob, $cat_cb, $check);
+ if ((++$n % 8192) == 0) {
+ diag "n=$n eql=$check->[0] neq=$check->[1]";
+ }
+ }
+ $git->cat_async_wait;
+});
+is($check->[0], $n, 'all messages round tripped');
+is($check->[1], 0, 'no messages failed to round trip');
+done_testing;