1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 22:28:47 -04:00

DBD-SQLite: also applied @CALL_FUNCS trick to t/08_busy.t

This commit is contained in:
Kenichi Ishigaki 2009-07-23 14:22:04 +00:00
parent 19b512b0b8
commit 5ff1f078d5
2 changed files with 71 additions and 149 deletions

View file

@ -8,60 +8,57 @@ BEGIN {
$^W = 1; $^W = 1;
} }
use t::lib::Test; use t::lib::Test qw/connect_ok @CALL_FUNCS/;
use Test::More; use Test::More;
BEGIN {
plan skip_all => 'requires DBI v1.608' if $DBI::VERSION < 1.608;
}
use Test::NoWarnings; use Test::NoWarnings;
plan tests => 12; plan tests => 11 * @CALL_FUNCS + 1;
my $dbh = connect_ok( foreach my $call_func (@CALL_FUNCS) {
my $dbh = connect_ok(
dbfile => 'foo', dbfile => 'foo',
RaiseError => 1, RaiseError => 1,
PrintError => 0, PrintError => 0,
AutoCommit => 0, AutoCommit => 0,
); );
my $dbh2 = connect_ok( my $dbh2 = connect_ok(
dbfile => 'foo', dbfile => 'foo',
RaiseError => 1, RaiseError => 1,
PrintError => 0, PrintError => 0,
AutoCommit => 0, AutoCommit => 0,
); );
ok($dbh2->sqlite_busy_timeout(3000)); ok($dbh2->$call_func(3000, 'busy_timeout'));
ok($dbh->do("CREATE TABLE Blah ( id INTEGER, val VARCHAR )")); ok($dbh->do("CREATE TABLE Blah ( id INTEGER, val VARCHAR )"));
ok($dbh->commit); ok($dbh->commit);
ok($dbh->do("INSERT INTO Blah VALUES ( 1, 'Test1' )")); ok($dbh->do("INSERT INTO Blah VALUES ( 1, 'Test1' )"));
my $start = time; my $start = time;
eval { eval {
$dbh2->do("INSERT INTO Blah VALUES ( 2, 'Test2' )"); $dbh2->do("INSERT INTO Blah VALUES ( 2, 'Test2' )");
}; };
ok($@); ok($@);
if ($@) { if ($@) {
print "# insert failed : $@"; print "# insert failed : $@";
$dbh2->rollback; $dbh2->rollback;
} }
$dbh->commit; $dbh->commit;
ok($dbh2->do("INSERT INTO Blah VALUES ( 2, 'Test2' )")); ok($dbh2->do("INSERT INTO Blah VALUES ( 2, 'Test2' )"));
$dbh2->commit; $dbh2->commit;
$dbh2->disconnect; $dbh2->disconnect;
undef($dbh2); undef($dbh2);
pipe(READER, WRITER); pipe(READER, WRITER);
my $pid = fork; my $pid = fork;
if (!defined($pid)) { if (!defined($pid)) {
# fork failed # fork failed
skip("No fork here", 1); skip("No fork here", 1);
skip("No fork here", 1); skip("No fork here", 1);
} elsif (!$pid) { } elsif (!$pid) {
# child # child
my $dbh2 = DBI->connect('dbi:SQLite:foo', '', '', my $dbh2 = DBI->connect('dbi:SQLite:foo', '', '',
{ {
@ -74,14 +71,19 @@ if (!defined($pid)) {
print WRITER "Ready\n"; print WRITER "Ready\n";
sleep(5); sleep(5);
$dbh2->commit; $dbh2->commit;
} else { $dbh2->disconnect;
exit;
} else {
# parent # parent
close WRITER; close WRITER;
my $line = <READER>; my $line = <READER>;
chomp($line); chomp($line);
ok($line, "Ready"); ok($line, "Ready");
ok($dbh->sqlite_busy_timeout(10000)); ok($dbh->$call_func(10000, 'busy_timeout'));
ok($dbh->do("INSERT INTO Blah VALUES (4, 'Test4' )")); ok($dbh->do("INSERT INTO Blah VALUES (4, 'Test4' )"));
$dbh->commit; $dbh->commit;
wait; wait;
$dbh->disconnect;
unlink 'foo';
}
} }

View file

@ -1,80 +0,0 @@
#!/usr/bin/perl
# Test that two processes can write at once, assuming we commit timely.
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test;
use Test::More tests => 12;
use Test::NoWarnings;
my $dbh = connect_ok(
dbfile => 'foo',
RaiseError => 1,
PrintError => 0,
AutoCommit => 0,
);
my $dbh2 = connect_ok(
dbfile => 'foo',
RaiseError => 1,
PrintError => 0,
AutoCommit => 0,
);
ok($dbh2->func(3000, 'busy_timeout'));
ok($dbh->do("CREATE TABLE Blah ( id INTEGER, val VARCHAR )"));
ok($dbh->commit);
ok($dbh->do("INSERT INTO Blah VALUES ( 1, 'Test1' )"));
my $start = time;
eval {
$dbh2->do("INSERT INTO Blah VALUES ( 2, 'Test2' )");
};
ok($@);
if ($@) {
print "# insert failed : $@";
$dbh2->rollback;
}
$dbh->commit;
ok($dbh2->do("INSERT INTO Blah VALUES ( 2, 'Test2' )"));
$dbh2->commit;
$dbh2->disconnect;
undef($dbh2);
pipe(READER, WRITER);
my $pid = fork;
if (!defined($pid)) {
# fork failed
skip("No fork here", 1);
skip("No fork here", 1);
} elsif (!$pid) {
# child
my $dbh2 = DBI->connect('dbi:SQLite:foo', '', '',
{
RaiseError => 1,
PrintError => 0,
AutoCommit => 0,
});
$dbh2->do("INSERT INTO Blah VALUES ( 3, 'Test3' )");
select WRITER; $| = 1; select STDOUT;
print WRITER "Ready\n";
sleep(5);
$dbh2->commit;
} else {
# parent
close WRITER;
my $line = <READER>;
chomp($line);
ok($line, "Ready");
ok($dbh->func(10000, 'busy_timeout'));
ok($dbh->do("INSERT INTO Blah VALUES (4, 'Test4' )"));
$dbh->commit;
wait;
}