aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Guldstrand <andreas.guldstrand@gmail.com>2016-05-27 01:13:08 +0200
committerAndreas Guldstrand <andreas.guldstrand@gmail.com>2016-05-27 01:13:08 +0200
commit42da333c39c591fb57ff2274fffa044f7f67c5e6 (patch)
tree0d400d18abf243bb82c25a998d0beefab37c9cf3
parentf3f086f97cff1517b3345f69fa1a136413933d19 (diff)
downloadsbotools2-42da333c39c591fb57ff2274fffa044f7f67c5e6.tar.xz
22-race.t: test race conditions in git_sbo_tree()
-rwxr-xr-xt/22-race.t51
1 files changed, 50 insertions, 1 deletions
diff --git a/t/22-race.t b/t/22-race.t
index 920635e..826ee22 100755
--- a/t/22-race.t
+++ b/t/22-race.t
@@ -9,8 +9,9 @@ use lib "$RealBin/../SBO-Lib/lib";
use SBO::Lib qw/ open_fh %config /;
use Capture::Tiny qw/ capture_merged /;
use File::Temp 'tempdir';
+use Cwd;
-plan tests => 4;
+plan tests => 8;
sub emulate_race {
my ($file, $caller) = @_;
@@ -64,3 +65,51 @@ sub emulate_race {
system('mv', "$sv_file.bak", $sv_file) if -e "$sv_file.bak";
}
+
+# 5-8: emulate races in git_sbo_tree
+SKIP: {
+ my $tempdir = tempdir(CLEANUP => 1);
+
+ my $repo = '/usr/sbo/repo';
+ system('mv', $repo, "$repo.bak");
+
+ capture_merged { system <<"GIT"; };
+ cd $tempdir
+ git init
+ mkdir -p test/nonexistentslackbuild
+ cp "$RealBin/nonexistentslackbuild/*" test/nonexistentslackbuild
+ git add test
+ git commit -m 'added test/nonexistentslackbuild'
+
+ cd /usr/sbo
+ git clone file://$tempdir repo
+GIT
+
+ no warnings 'redefine';
+ *_race::cond = sub { system('rm', '-rf', $repo) if $_[0] eq '$repo_path can be deleted after -d check' };
+
+ my $res;
+ my $out = capture_merged { $res = SBO::Lib::git_sbo_tree("file://$tempdir"); };
+
+ is ($out, '', 'git_sbo_tree() no output');
+ is ($res, 0, 'git_sbo_tree() returned 0');
+
+ capture_merged { system('git', 'clone', "file://$tempdir", $repo); };
+ my $cwd = getcwd();
+ mkdir "$tempdir/bar";
+ chdir "$tempdir/bar";
+ *_race::cond = sub {
+ system('rm', '-rf', "$repo/.git") if $_[0] eq 'git repo could be changed or deleted here';
+ system('rmdir', "$tempdir/bar") if $_[0] eq '$cwd could be deleted here';
+ };
+
+ undef $res;
+ $out = capture_merged { $res = SBO::Lib::git_sbo_tree("file://$tempdir"); };
+
+ is ($res, 0, 'git_sbo_tree() returned 0');
+ is ($out, "fatal: Not a git repository (or any of the parent directories): .git\n", 'git_sbo_tree() gave correct output');
+
+ chdir $cwd;
+ system('rm', '-rf', $repo);
+ system('mv', "$repo.bak", $repo);
+}