Restore ability to handle underdefined root (t/prefetch/incomplete.t)
[dbsrgits/DBIx-Class.git] / t / zzzzzzz_sqlite_deadlock.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 use lib 't/lib';
7 use DBICTest::RunMode;
8
9 if ( DBICTest::RunMode->is_plain ) {
10   plan( skip_all => "Skipping test on plain module install" );
11 }
12
13 use Test::Exception;
14 use DBICTest;
15 use File::Temp ();
16
17 plan tests => 2;
18 my $wait_for = 120;  # how many seconds to wait
19
20 # don't lock anything - this is a tempfile anyway
21 $ENV{DBICTEST_LOCK_HOLDER} = -1;
22
23 for my $close (0,1) {
24
25   my $tmp = File::Temp->new(
26     UNLINK => 1,
27     DIR => 't/var',
28     SUFFIX => '.db',
29     TEMPLATE => 'DBIxClass-XXXXXX',
30     EXLOCK => 0,  # important for BSD and derivatives
31   );
32
33   my $tmp_fn = $tmp->filename;
34   close $tmp if $close;
35
36   local $SIG{ALRM} = sub { die sprintf (
37     "Timeout of %d seconds reached (tempfile still open: %s)",
38     $wait_for, $close ? 'No' : 'Yes'
39   )};
40
41   alarm $wait_for;
42
43   lives_ok (sub {
44     my $schema = DBICTest::Schema->connect ("DBI:SQLite:$tmp_fn");
45     $schema->storage->dbh_do(sub { $_[1]->do('PRAGMA synchronous = OFF') });
46     DBICTest->deploy_schema ($schema);
47     DBICTest->populate_schema ($schema);
48   });
49
50   alarm 0;
51 }