fixed up the relicant status tests to exclude them if the database is not a real...
John Napiorkowski [Fri, 9 May 2008 00:06:42 +0000 (00:06 +0000)]
lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
lib/DBIx/Class/Storage/DBI/mysql.pm
t/93storage_replication.t

index 5bf61e6..1d65b85 100644 (file)
@@ -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\:.+\:(.+)$/);
index 5c59d18..dadcbf0 100644 (file)
@@ -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;
index eb31c81..a4b377e 100644 (file)
@@ -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;