diff --git a/lib/ReplicaLagLimiter.pm b/lib/ReplicaLagLimiter.pm index 58c77463..2bf91474 100644 --- a/lib/ReplicaLagLimiter.pm +++ b/lib/ReplicaLagLimiter.pm @@ -57,7 +57,7 @@ sub new { my ( $class, %args ) = @_; my @required_args = qw(spec slaves get_lag initial_n initial_t target_t); foreach my $arg ( @required_args ) { - die "I need a $arg argument" unless $args{$arg}; + die "I need a $arg argument" unless defined $args{$arg}; } my ($spec) = @args{@required_args}; @@ -146,7 +146,7 @@ sub update { # Progress - object to report waiting # # Returns: -# True if all slaves catch up before timeout, else die unless continue is true +# 1 if all slaves catch up before timeout, else 0 if continue=yes, else die. sub wait { my ( $self, %args ) = @_; my @required_args = qw(); @@ -196,13 +196,19 @@ sub wait { $slave = $slaves->[++$slave_no]; } } - if ( $slave_no < @$slaves && $self->{continue} eq 'no' ) { - die "Timeout waiting for replica " . $slaves->[$slave_no]->{dsn}->{n} - . " to catch up\n"; + if ( $slave_no < @$slaves ) { + if ( $self->{continue} eq 'no' ) { + die "Timeout waiting for replica " . $slaves->[$slave_no]->{dsn}->{n} + . " to catch up\n"; + } + else { + MKDEBUG && _d('Some slave are not caught up'); + return 0; # not ready + } } MKDEBUG && _d('All slaves caught up'); - return 1; + return 1; # ready } sub _d { diff --git a/t/lib/NibbleIterator.t b/t/lib/NibbleIterator.t index 65d52381..82804273 100644 --- a/t/lib/NibbleIterator.t +++ b/t/lib/NibbleIterator.t @@ -38,7 +38,7 @@ if ( !$dbh ) { plan skip_all => 'Cannot connect to sandbox master'; } else { - plan tests => 20; + plan tests => 21; } my $q = new Quoter(); @@ -447,6 +447,27 @@ is_deeply( "Change chunk size while nibbling" ) or print STDERR Dumper(\@rows); +# ############################################################################ +# Nibble one row at a time. +# ############################################################################ +$ni = make_nibble_iter( + sql_file => "a-z.sql", + db => 'test', + tbl => 't', + argv => [qw(--databases test --chunk-size 1)], +); + +@rows = (); +while (my $row = $ni->next()) { + push @rows, @$row; +} + +is_deeply( + \@rows, + [ ('a'..'z') ], + "Nibble by 1 row" +); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/lib/ReplicaLagLimiter.t b/t/lib/ReplicaLagLimiter.t index 9604d302..64cd5f93 100644 --- a/t/lib/ReplicaLagLimiter.t +++ b/t/lib/ReplicaLagLimiter.t @@ -197,8 +197,8 @@ $rll = new ReplicaLagLimiter( @lag = (5, 0, 0); is( $rll->wait(), - 1, - "wait() returns 1 despite timeout if continue=yes" + 0, + "wait() returns 0 if timeout and continue=yes" ); # #############################################################################