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