From: John Napiorkowski Date: Fri, 9 May 2008 00:06:42 +0000 (+0000) Subject: fixed up the relicant status tests to exclude them if the database is not a real... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f797e89e547c902c2a5cb1669f75c2bdb7769af7;p=dbsrgits%2FDBIx-Class-Historic.git fixed up the relicant status tests to exclude them if the database is not a real replicating setup, removed some debug code, got the lag_behind_master and is_replicating methods working properly. --- diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm index 5bf61e6..1d65b85 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm @@ -119,7 +119,6 @@ sub connect_replicants { my $replicant = $self->create_replicant($schema); $replicant->connect_info($connect_info); $replicant->ensure_connected; - DBIx::Class::Storage::DBI::Replicated::Replicant->meta->apply($replicant); my ($key) = ($connect_info->[0]=~m/^dbi\:.+\:(.+)$/); diff --git a/lib/DBIx/Class/Storage/DBI/mysql.pm b/lib/DBIx/Class/Storage/DBI/mysql.pm index 5c59d18..dadcbf0 100644 --- a/lib/DBIx/Class/Storage/DBI/mysql.pm +++ b/lib/DBIx/Class/Storage/DBI/mysql.pm @@ -33,14 +33,14 @@ sub _svp_rollback { $self->dbh->do("ROLLBACK TO SAVEPOINT $name") } - + sub is_replicating { - my $self = shift @_; + my $status = shift->dbh->selectrow_hashref('show slave status'); + return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes'); } sub lag_behind_master { - my $self = shift @_; - return $self->dbh->selectrow_hashref('show slave status'); + return shift->dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master}; } 1; diff --git a/t/93storage_replication.t b/t/93storage_replication.t index eb31c81..a4b377e 100644 --- a/t/93storage_replication.t +++ b/t/93storage_replication.t @@ -8,7 +8,7 @@ BEGIN { eval "use Moose; use Test::Moose"; plan $@ ? ( skip_all => 'needs Moose for testing' ) - : ( tests => 41 ); + : ( tests => 43 ); } use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool'; @@ -365,10 +365,22 @@ ok $replicated->schema->resultset('Artist')->find(2) ## Getting slave status tests -use Data::Dump qw/dump/; -my $lag1 = $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master; -warn dump $lag1; - +SKIP: { + ## We skip this tests unless you have a custom replicants, since the default + ## sqlite based replication tests don't support these functions. + + skip 'Cannot Test Replicant Status on Non Replicating Database', 2 + unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"}; + + $replicated->replicate; ## Give the slaves a chance to catchup. + + ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating + => 'Replicants are replicating'; + + is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0 + => 'Replicant is zero seconds behind master'; +} + ## Delete the old database files $replicated->cleanup;