From: janw Date: Thu, 26 Feb 2009 14:49:17 +0000 (+0000) Subject: Allow better debugging. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5297ca18c2b3d21e62c1b982ca2a3845f55ef866;p=gosa.git Allow better debugging. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13467 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/tests/sqlite-check-concurrency.pl b/gosa-si/tests/sqlite-check-concurrency.pl index d6c4ce9c1..dfd258340 100755 --- a/gosa-si/tests/sqlite-check-concurrency.pl +++ b/gosa-si/tests/sqlite-check-concurrency.pl @@ -5,24 +5,30 @@ use strict; use warnings; use DBI; +use Data::Dumper; use Time::HiRes qw(usleep); use Fcntl ':flock'; use threads; my %threads; # Count of threads, if > 1 it corrupts the db -my $count= 1; +my $count= 10; my $db_name= "./test.sqlite"; +my $lock = $db_name.".si.lock"; +if(stat($lock)) { + unlink($lock); +} -unlink $db_name; -unlink $db_name.".si.lock"; +if(stat($db_name)) { + unlink($db_name) +} for(my $i=0;$i<$count;$i++) { $threads{$i}= threads->create(\&check_database); } foreach my $thread (threads->list()) { - print $thread->tid()."\n"; + $thread->join(); } sub check_database { @@ -33,37 +39,30 @@ sub check_database { return; } - sub new { - my $class = shift; - my $db_name = shift; + my $class = shift; + my $db_name = shift; - my $lock = $db_name.".si.lock"; - # delete existing lock - instance should be running only once - if(stat($lock)) { - print STDERR "DEBUG: Removed existing lock file $lock."; - unlink($lock); - } - my $self = {dbh=>undef,db_name=>undef,db_lock=>undef,db_lock_handle=>undef}; - my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name", "", "", {RaiseError => 0, AutoCommit => 0}); - $self->{dbh} = $dbh; - $self->{db_name} = $db_name; - $self->{db_lock} = $lock; - bless($self,$class); - return($self); + my $self = {dbh=>undef,db_name=>undef,db_lock=>undef,db_lock_handle=>undef}; + my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name", "", "", {RaiseError => 1, AutoCommit => 1}); + $self->{dbh} = $dbh; + $self->{db_name} = $db_name; + $self->{db_lock} = $lock; + bless($self,$class); + return($self); } sub lock { - my $self = shift; - open($self->{db_lock_handle}, ">>".($self->{db_lock})) unless ref $self->{db_lock_handle}; - flock($self->{db_lock_handle},LOCK_EX); - seek($self->{db_lock_handle}, 0, 2); + my $self = shift; + open($self->{db_lock_handle}, ">>".($self->{db_lock})) unless ref $self->{db_lock_handle}; + flock($self->{db_lock_handle},LOCK_EX); + seek($self->{db_lock_handle}, 0, 2); } sub unlock { - my $self = shift; - flock($self->{db_lock_handle},LOCK_UN); + my $self = shift; + flock($self->{db_lock_handle},LOCK_UN); } sub run_test { @@ -71,13 +70,23 @@ sub run_test { my $table_name= shift; my $sql= "CREATE TABLE IF NOT EXISTS $table_name (id INTEGER, value VARCHAR(255))"; $self->lock(); - $self->{dbh}->do($sql); + eval { + $self->{dbh}->do($sql); + }; + if($@) { + print STDERR Dumper($@); + } $self->unlock(); - - for(my $i=0;$i<10000;$i++) { - $sql= "INSERT INTO $table_name VALUES ($i, 'test $i')"; - $self->lock(); - $self->{dbh}->do($sql); - $self->unlock(); + + for(my $i=0;$i<100;$i++) { + $sql= "INSERT INTO $table_name VALUES ($i, 'test $i')"; + $self->lock(); + eval { + $self->{dbh}->do($sql); + }; + if($@) { + print STDERR Dumper($@); + } + $self->unlock(); } }