Reduce amount of initial connects during non-SQLite test-RDBMS lock-grabs
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / RunMode.pm
index 348c8ea..ee16bc1 100644 (file)
@@ -19,6 +19,7 @@ use Path::Class qw/file dir/;
 use Fcntl ':DEFAULT';
 use File::Spec ();
 use File::Temp ();
+use DBICTest::Util 'local_umask';
 
 _check_author_makefile() unless $ENV{DBICTEST_NO_MAKEFILE_VERIFICATION};
 
@@ -43,26 +44,28 @@ sub tmpdir {
     else {
       # make sure we can actually create and sysopen a file in this dir
       local $@;
-      my $tfh;
+      my $u = local_umask(0); # match the umask we use in DBICTest(::Schema)
+      my $tempfile = '<NONCREATABLE>';
       eval {
-        $tfh = File::Temp->new(
-          TEMPLATE => '_dbictest_writability_XXXXXX',
+        $tempfile = File::Temp->new(
+          TEMPLATE => '_dbictest_writability_test_XXXXXX',
           DIR => "$dir",
           UNLINK => 1,
         );
-        my $fn = "$tfh";
-        close $tfh or die "closing $fn failed: $!\n";
-        sysopen (my $tfh2, $fn, O_RDWR) or die "reopening $fn failed: $!\n";
-        print $tfh2 'deadbeef' x 1024 or die "printing to $fn failed: $!\n";
-        close $tfh2 or die "closing $fn failed: $!\n";
+        close $tempfile or die "closing $tempfile failed: $!\n";
+
+        sysopen (my $tempfh2, "$tempfile", O_RDWR) or die "reopening $tempfile failed: $!\n";
+        print $tempfh2 'deadbeef' x 1024 or die "printing to $tempfile failed: $!\n";
+        close $tempfh2 or die "closing $tempfile failed: $!\n";
         1;
       } or do {
         chomp( my $err = $@ );
-        my @x_tests = map { (defined $_) ? ( $_ ? 1 : 0 ) : 'U' } map {(-e, -d, -f, -r, -w, -x, -o)} ("$dir", "$tfh");
-        $reason_dir_unusable = sprintf <<"EOE", "$tfh"||'', $err, scalar $>, scalar $), (stat($dir))[4,5,2], @x_tests;
+        my @x_tests = map { (defined $_) ? ( $_ ? 1 : 0 ) : 'U' } map {(-e, -d, -f, -r, -w, -x, -o)} ("$dir", "$tempfile");
+        $reason_dir_unusable = sprintf <<"EOE", "$tempfile"||'', $err, scalar $>, scalar $), umask(), (stat($dir))[4,5,2], @x_tests;
 File::Spec->tmpdir returned a directory which appears to be non-writeable:
 Error encountered while testing '%s': %s
 Process EUID/EGID: %s / %s
+Effective umask:   %o
 TmpDir UID/GID:    %s / %s
 TmpDir StatMode:   %o
 TmpDir X-tests:    -e:%s -d:%s -f:%s -r:%s -w:%s -x:%s -o:%s
@@ -195,12 +198,20 @@ sub is_author {
 
 sub is_smoker {
   return
-    ( ($ENV{TRAVIS}||'') eq 'true' )
+    __PACKAGE__->is_ci
       ||
     ( $ENV{AUTOMATED_TESTING} && ! $ENV{PERL5_CPANM_IS_RUNNING} && ! $ENV{RELEASE_TESTING} )
   ;
 }
 
+sub is_ci {
+  return (
+    ($ENV{TRAVIS}||'') eq 'true'
+      and
+    ($ENV{TRAVIS_REPO_SLUG}||'') =~ m|\w+/dbix-class$|
+  )
+}
+
 sub is_plain {
   return (! __PACKAGE__->is_smoker && ! __PACKAGE__->is_author && ! $ENV{RELEASE_TESTING} )
 }