lei/store: stop shard workers + cat-file on idle
[public-inbox.git] / t / io.t
blob91f935263b77b0ad8f039258661599ab39d2d781
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 PublicInbox::TestCommon;
6 my $tmpdir = tmpdir;
7 use_ok 'PublicInbox::IO';
8 use PublicInbox::Spawn qw(which run_qx);
10 # test failures:
11 SKIP: {
12 my $strace = strace_inject;
13 my $env = { PERL5LIB => join(':', @INC) };
14 my $opt = { 1 => \my $out, 2 => \my $err };
15 my $dst = "$tmpdir/dst";
16 my $tr = "$tmpdir/tr";
17 my $cmd = [ $strace, "-o$tr", "-P$dst",
18                 '-e', 'inject=writev,write:error=EIO',
19                 $^X, qw(-w -MPublicInbox::IO=write_file -e),
20                 q[write_file '>', $ARGV[0], 'hello world'], $dst ];
21 xsys($cmd, $env, $opt);
22 isnt($?, 0, 'write failed');
23 like($err, qr/\bclose\b/, 'close error noted');
24 is(-s $dst, 0, 'file created and empty after EIO');
25 } # /SKIP
27 PublicInbox::IO::write_file '>:unix', "$tmpdir/f", "HI\n";
28 is(-s "$tmpdir/f", 3, 'write_file works w/ IO layer');
29 PublicInbox::IO::write_file '>>', "$tmpdir/f", "HI\n";
30 is(-s "$tmpdir/f", 6, 'write_file can append');
32 is PublicInbox::IO::try_cat("$tmpdir/non-existent"), '',
33         "try_cat on non-existent file returns `'";
35 done_testing;