From d5c6e519141e618da212053c00e3e26d8d4932dc Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Thu, 16 Sep 2010 06:59:36 +0000 Subject: [PATCH] resolved #61355 --- Changes | 3 +++ t/02_logon.t | 5 ++++- t/08_busy.t | 8 +++++--- t/28_schemachange.t | 3 ++- t/34_online_backup.t | 9 +++++---- t/lib/Test.pm | 16 ++++++++++++---- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Changes b/Changes index 6d99154..c7b9a39 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Changes for Perl extension DBD-SQLite +1.32_01 to be released + - Resolved #61355: Fails testing in parallel (ISHIGAKI) + 1.31 Wed 15 Sep 2010 - Production release, identical to 1.30_06 diff --git a/t/02_logon.t b/t/02_logon.t index 4629c84..3061514 100644 --- a/t/02_logon.t +++ b/t/02_logon.t @@ -33,9 +33,12 @@ foreach my $call_func (@CALL_FUNCS) { unless ( $] >= 5.008005 ) { skip( 'Unicode is not supported before 5.8.5', 2 ); } - my $dbh = DBI->connect( 'dbi:SQLite:dbname=foo;sqlite_unicode=1', '', '' ); + my $file = 'foo'.$$; + my $dbh = DBI->connect( "dbi:SQLite:dbname=$file;sqlite_unicode=1", '', '' ); isa_ok( $dbh, 'DBI::db' ); is( $dbh->{sqlite_unicode}, 1, 'Unicode is on' ); + $dbh->disconnect; + unlink $file; } # Connect to a memory database diff --git a/t/08_busy.t b/t/08_busy.t index daad822..6968132 100644 --- a/t/08_busy.t +++ b/t/08_busy.t @@ -8,7 +8,7 @@ BEGIN { $^W = 1; } -use t::lib::Test qw/connect_ok @CALL_FUNCS/; +use t::lib::Test qw/connect_ok dbfile @CALL_FUNCS/; use Test::More; use Test::NoWarnings; @@ -30,6 +30,8 @@ foreach my $call_func (@CALL_FUNCS) { AutoCommit => 0, ); + my $dbfile = dbfile('foo'); + # NOTE: Let's make it clear what we're doing here. # $dbh starts locking with the first INSERT statement. # $dbh2 tries to INSERT, but as the database is locked, @@ -77,7 +79,7 @@ foreach my $call_func (@CALL_FUNCS) { skip("No fork here", 1); } elsif (!$pid) { # child - my $dbh2 = DBI->connect('dbi:SQLite:foo', '', '', + my $dbh2 = DBI->connect("dbi:SQLite:$dbfile", '', '', { RaiseError => 1, PrintError => 0, @@ -108,6 +110,6 @@ foreach my $call_func (@CALL_FUNCS) { } wait; $dbh->disconnect; - unlink 'foo'; + unlink $dbfile; } } diff --git a/t/28_schemachange.t b/t/28_schemachange.t index 3aa5d2c..66cef08 100644 --- a/t/28_schemachange.t +++ b/t/28_schemachange.t @@ -24,6 +24,7 @@ SCOPE: { ok( $dbh->do($create2), $create2 ); ok( $dbh->disconnect, '->disconnect ok' ); } +my $dbfile = dbfile('foo'); my $pid; # diag("Forking... ($$)"); @@ -36,7 +37,7 @@ if ( not defined( $pid = fork() ) ) { # diag("Child starting... ($$)"); my $dbh = DBI->connect( - 'dbi:SQLite:dbname=foo', '', '' + "dbi:SQLite:dbname=$dbfile", '', '' ) or die 'connect failed'; $dbh->do($drop2) or die "DROP ok"; $dbh->disconnect or die "disconnect ok"; diff --git a/t/34_online_backup.t b/t/34_online_backup.t index 8a4ce95..0675f2e 100644 --- a/t/34_online_backup.t +++ b/t/34_online_backup.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use t::lib::Test qw/connect_ok @CALL_FUNCS/; +use t::lib::Test qw/connect_ok dbfile @CALL_FUNCS/; BEGIN { use DBD::SQLite; @@ -22,6 +22,7 @@ plan tests => 6 * @CALL_FUNCS + 1; foreach my $call_func (@CALL_FUNCS) { # Connect to the test db and add some stuff: my $foo = connect_ok( dbfile => 'foo', RaiseError => 1 ); + my $dbfile = dbfile('foo'); $foo->do( 'CREATE TABLE online_backup_test( id INTEGER PRIMARY KEY, foo INTEGER )' ); @@ -38,7 +39,7 @@ foreach my $call_func (@CALL_FUNCS) { { RaiseError => 1 } ); - ok($dbh->$call_func('foo', 'backup_from_file')); + ok($dbh->$call_func($dbfile, 'backup_from_file')); { my ($count) = $dbh->selectrow_array( @@ -54,7 +55,7 @@ foreach my $call_func (@CALL_FUNCS) { $dbh->do("INSERT INTO online_backup_test2 (foo) VALUES ($$)"); # backup to file (foo): - ok($dbh->$call_func('foo', 'backup_to_file')); + ok($dbh->$call_func($dbfile, 'backup_to_file')); $dbh->disconnect; @@ -71,5 +72,5 @@ foreach my $call_func (@CALL_FUNCS) { } $dbh->disconnect; - unlink 'foo'; + unlink $dbfile; } diff --git a/t/lib/Test.pm b/t/lib/Test.pm index 2961e88..f2addf5 100644 --- a/t/lib/Test.pm +++ b/t/lib/Test.pm @@ -9,10 +9,11 @@ use Test::More (); use vars qw{$VERSION @ISA @EXPORT @CALL_FUNCS}; my $parent; +my %dbfiles; BEGIN { $VERSION = '1.31'; @ISA = 'Exporter'; - @EXPORT = qw/connect_ok dies @CALL_FUNCS/; + @EXPORT = qw/connect_ok dies dbfile @CALL_FUNCS/; # Allow tests to load modules bundled in /inc unshift @INC, 'inc'; @@ -23,12 +24,18 @@ BEGIN { # Always load the DBI module use DBI (); +sub dbfile { $dbfiles{$_[0]} } + # Delete temporary files sub clean { return if $$ != $parent; - unlink( 'foo' ); - unlink( 'foo-journal' ); + for my $dbfile (values %dbfiles) { + next if $dbfile eq ':memory:'; + unlink $dbfile if -f $dbfile; + my $journal = $dbfile . '-journal'; + unlink $journal if -f $journal; + } } # Clean up temporary test files both at the beginning and end of the @@ -40,7 +47,8 @@ END { clean() } sub connect_ok { my $attr = { @_ }; my $dbfile = delete $attr->{dbfile} || ':memory:'; - my @params = ( "dbi:SQLite:dbname=$dbfile", '', '' ); + $dbfiles{$dbfile} = ($dbfile ne ':memory:') ? $dbfile . $$ : $dbfile; + my @params = ( "dbi:SQLite:dbname=$dbfiles{$dbfile}", '', '' ); if ( %$attr ) { push @params, $attr; }