diff options
author | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-05-12 18:32:33 +0200 |
---|---|---|
committer | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-05-12 18:32:33 +0200 |
commit | 343c71cfa9f54d13f61727bf10cf9dc7bdf44949 (patch) | |
tree | 61f11f2dddec5b42a19bf3b1a88a341d76f0b1f2 /t | |
parent | c13edd93d68415fd4dce8af5c1258001b1d6194c (diff) | |
download | sbotools2-343c71cfa9f54d13f61727bf10cf9dc7bdf44949.tar.xz |
25-race.t: Add test for race in open_fh
Diffstat (limited to 't')
-rwxr-xr-x | t/24-race.t | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/t/24-race.t b/t/24-race.t new file mode 100755 index 0000000..07b9b74 --- /dev/null +++ b/t/24-race.t @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use Test::Exit; +use FindBin '$RealBin'; +use lib "$RealBin/../SBO-Lib/lib"; +use SBO::Lib qw/ open_fh /; +use Capture::Tiny qw/ capture_merged /; +use File::Temp 'tempdir'; + +plan tests => 1; + +sub emulate_race { + my ($file, $caller) = @_; + $caller = "SBO::Lib::$caller"; + + no warnings 'redefine'; + *_race::cond = sub { unlink $file if $caller eq (caller(1))[3]; }; +} + +# 1: emulate race condition for open_fh +{ + my $tempdir = tempdir(CLEANUP => 1); + my $file = "$tempdir/foo"; + system('touch', $file); + + emulate_race($file, 'open_fh'); + + my ($fh, $exit) = open_fh $file, '<'; + is ($exit, 6, 'open_fh returned exit value 6'); +} |