diff --git a/t/28_schemachange.t b/t/28_schemachange.t index fed69d2..09b2ba2 100644 --- a/t/28_schemachange.t +++ b/t/28_schemachange.t @@ -9,7 +9,7 @@ BEGIN { $^W = 1; } -use Test::More tests => 5; +use Test::More tests => 9; use t::lib::Test; my $create1 = 'CREATE TABLE table1 (id INTEGER NOT NULL, name CHAR (64) NOT NULL)'; @@ -17,15 +17,11 @@ my $create2 = 'CREATE TABLE table2 (id INTEGER NOT NULL, name CHAR (64) NOT NULL my $drop1 = 'DROP TABLE table1'; my $drop2 = 'DROP TABLE table2'; -# diag("Parent starting... ($$)"); - -# Create the tables -SCOPE: { - my $dbh = DBI->connect('dbi:SQLite:dbname=foo', '', '') or die 'connect failed'; - $dbh->do($create1) or die '$create1 failed'; - $dbh->do($create2) or die '$create2 failed'; - $dbh->disconnect or die 'disconnect failed'; -} +# diag("Parent connecting... ($$)\n"); +my $dbh = connect_ok(); +ok( $dbh->do($create1), $create1 ); +ok( $dbh->do($create2), $create2 ); +ok( $dbh->disconnect, '->disconnect ok' ); my $pid; # diag("Forking... ($$)"); @@ -33,25 +29,29 @@ if ( not defined( $pid = fork() ) ) { die("fork: $!"); } elsif ( $pid == 0 ) { - # Child process + # Pause to let the parent connect + sleep(2); + # diag("Child starting... ($$)"); - my $dbh = connect_ok(); - ok( $dbh->do($drop2), $drop2 ); - ok( $dbh->disconnect, '->disconnect ok' ); + my $dbh = DBI->connect( + 'dbi:SQLite:dbname=foo', '', '' + ) or die 'connect failed'; + $dbh->do($drop2) or die "DROP ok"; + $dbh->disconnect or die "disconnect ok"; # diag("Child exiting... ($$)"); + exit(0); -} else { +} + +SCOPE: { # Parent process # diag("Waiting for child... ($$)"); ok( waitpid($pid, 0) != -1, "waitpid" ); -} - -# Make sure the child actually deleted table2 -SCOPE: { + # Make sure the child actually deleted table2 my $dbh = connect_ok(); - ok( $dbh->do($drop1), $drop1 ); - ok( $dbh->do($create2), $create2 ); + ok( $dbh->do($drop1), $drop1 ) or diag("Error: '$DBI::errstr'"); + ok( $dbh->do($create2), $create2 ) or diag("Error: '$DBI::errstr'"); ok( $dbh->disconnect, '->disconnect ok' ); }