lei/store: stop shard workers + cat-file on idle
[public-inbox.git] / t / gzip_filter.t
blob97eac2d04851e1f274327223340b991f3e1b8f54
1 #!perl -w
2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use v5.12;
5 use IO::Handle (); # autoflush
6 use Fcntl qw(SEEK_SET);
7 use PublicInbox::TestCommon;
8 require_mods(qw(Compress::Zlib IO::Uncompress::Gunzip));
9 require_ok 'PublicInbox::GzipFilter';
12         open my $fh, '+>', undef or die "open: $!";
13         open my $dup, '>&', $fh or die "dup $!";
14         $dup->autoflush(1);
15         my $filter = PublicInbox::GzipFilter->new->attach($dup);
16         ok($filter->write("hello"), 'wrote something');
17         ok($filter->write("world"), 'wrote more');
18         $filter->close;
19         seek($fh, 0, SEEK_SET) or die;
20         IO::Uncompress::Gunzip::gunzip($fh => \(my $buf));
21         is($buf, 'helloworld', 'buffer matches');
25         pipe(my ($r, $w)) or die "pipe: $!";
26         $w->autoflush(1);
27         close $r or die;
28         my $filter = PublicInbox::GzipFilter->new->attach($w);
29         my $sigpipe;
30         local $SIG{PIPE} = sub { $sigpipe = 1 };
31         open my $fh, '<', 'COPYING' or die "open(COPYING): $!";
32         my $buf = do { local $/; <$fh> };
33         while ($filter->write($buf .= rand)) {}
34         ok($sigpipe, 'got SIGPIPE') or diag "\$!=$!";
35         close $w;
37 done_testing;