From 903c74de0b1feae03fdeb8a7ce68b6327699e3a2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 5 Jul 2020 23:27:32 +0000 Subject: mbox: async blob fetch for "single message" raw mboxrd This restores gzip-by-default behavior for /$INBOX/$MSGID/raw endpoints for all indexed inboxes. Unindexed v1 inboxes will remain uncompressed, for now. --- t/psgi_v2.t | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 't') diff --git a/t/psgi_v2.t b/t/psgi_v2.t index 8f75a3fb..90a710a4 100644 --- a/t/psgi_v2.t +++ b/t/psgi_v2.t @@ -103,7 +103,7 @@ $mids = mids($mime->header_obj); my $third = $mids->[-1]; $im->done; -test_psgi(sub { $www->call(@_) }, sub { +my $client = sub { my ($cb) = @_; $res = $cb->(GET("/v2test/$third/raw")); $raw = $res->content; @@ -122,12 +122,19 @@ test_psgi(sub { $www->call(@_) }, sub { SKIP: { eval { require IO::Uncompress::Gunzip }; - skip 'IO::Uncompress::Gunzip missing', 4 if $@; + skip 'IO::Uncompress::Gunzip missing', 6 if $@; + my ($in, $out, $status); + my $req = GET('/v2test/a-mid@b/raw'); + $req->header('Accept-Encoding' => 'gzip'); + $res = $cb->($req); + is($res->header('Content-Encoding'), 'gzip', 'gzip encoding'); + $in = $res->content; + IO::Uncompress::Gunzip::gunzip(\$in => \$out); + is($out, $raw, 'gzip response matches'); $res = $cb->(GET('/v2test/a-mid@b/t.mbox.gz')); - my $out; - my $in = $res->content; - my $status = IO::Uncompress::Gunzip::gunzip(\$in => \$out); + $in = $res->content; + $status = IO::Uncompress::Gunzip::gunzip(\$in => \$out); unlike($out, qr/^From oldbug/sm, 'buggy "From_" line omitted'); like($out, qr/^hello world$/m, 'got first in t.mbox.gz'); like($out, qr/^hello world!$/m, 'got second in t.mbox.gz'); @@ -187,7 +194,34 @@ test_psgi(sub { $www->call(@_) }, sub { like($raw, qr!>\Q$mid\E!s, "Message-ID $mid shown"); } like($raw, qr/\b3\+ messages\b/, 'thread overview shown'); +}; +test_psgi(sub { $www->call(@_) }, $client); +SKIP: { + require_mods(qw(Plack::Test::ExternalServer), 37); + my $cfgpath = "$inboxdir/$$.config"; + open my $fh, '>', $cfgpath or BAIL_OUT $!; + print $fh < $cfgpath }; + my $sock = tcp_server() or die; + my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err); + my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ]; + my $td = start_script($cmd, $env, { 3 => $sock }); + my ($h, $p) = ($sock->sockhost, $sock->sockport); + local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p"; + Plack::Test::ExternalServer::test_psgi(client => $client); + $td->join('TERM'); + open $fh, '<', $err or BAIL_OUT $!; + is(do { local $/; <$fh> }, '', 'no errors'); +}; + +test_psgi(sub { $www->call(@_) }, sub { + my ($cb) = @_; my $exp = [ qw( ) ]; $mime->header_set('Message-Id', @$exp); $mime->header_set('Subject', '4th dupe'); @@ -208,7 +242,7 @@ test_psgi(sub { $www->call(@_) }, sub { $res = $cb->(GET('/v2test/reuse@mid/T/')); $raw = $res->content; like($raw, qr/\b4\+ messages\b/, 'thread overview shown with /T/'); - @over = ($raw =~ m/^\d{4}-\d+-\d+\s+\d+:\d+ (.+)$/gm); + my @over = ($raw =~ m/^\d{4}-\d+-\d+\s+\d+:\d+ (.+)$/gm); is_deeply(\@over, [ '