Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class.git] / xt / extra / sqlite_deadlock.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
d7b94f7a 3use strict;
4use warnings;
5
6use Test::More;
554484cb 7use Test::Exception;
8use File::Temp ();
d7b94f7a 9
c0329273 10
8d6b1478 11use DBICTest;
8d6b1478 12
d7b94f7a 13plan tests => 2;
39c9c72d 14my $wait_for = 120; # how many seconds to wait
d7b94f7a 15
8d6b1478 16# don't lock anything - this is a tempfile anyway
17$ENV{DBICTEST_LOCK_HOLDER} = -1;
18
d7b94f7a 19for my $close (0,1) {
20
f86589ef 21 my $tmp = File::Temp->new(
22 UNLINK => 1,
8d6b1478 23 DIR => 't/var',
24 SUFFIX => '.db',
25 TEMPLATE => 'DBIxClass-XXXXXX',
f86589ef 26 EXLOCK => 0, # important for BSD and derivatives
27 );
28
d7b94f7a 29 my $tmp_fn = $tmp->filename;
30 close $tmp if $close;
31
32 local $SIG{ALRM} = sub { die sprintf (
33 "Timeout of %d seconds reached (tempfile still open: %s)",
34 $wait_for, $close ? 'No' : 'Yes'
35 )};
36
37 alarm $wait_for;
38
39 lives_ok (sub {
40 my $schema = DBICTest::Schema->connect ("DBI:SQLite:$tmp_fn");
8d6b1478 41 $schema->storage->dbh_do(sub { $_[1]->do('PRAGMA synchronous = OFF') });
d7b94f7a 42 DBICTest->deploy_schema ($schema);
8d6b1478 43 DBICTest->populate_schema ($schema);
d7b94f7a 44 });
45
46 alarm 0;
47}