Implement retry_on_error for Pipeline processes. Retry iteration proc twice, then fail completely. Fix mirror.t.

This commit is contained in:
Daniel Nichter
2012-05-23 16:07:05 -06:00
parent 74b1caa241
commit 491c076e75
5 changed files with 105 additions and 22 deletions

View File

@@ -9,7 +9,7 @@ BEGIN {
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 10;
use Test::More tests => 11;
use Time::HiRes qw(usleep);
@@ -206,11 +206,13 @@ is(
$oktorun = 1;
$pipeline = new Pipeline(continue_on_error=>1);
my @die = qw(1 0);
my @called = ();
my @die = qw(1 0);
$pipeline->add(
name => 'proc1',
process => sub {
my ( $args ) = @_;
push @called, 'proc1';
die "I'm an error" if shift @die;
return $args;
},
@@ -218,7 +220,7 @@ $pipeline->add(
$pipeline->add(
name => 'proc2',
process => sub {
print "proc2";
push @called, 'proc2';
$oktorun = 0;
return;
},
@@ -229,12 +231,48 @@ $output = output(
stderr => 1,
);
like(
$output,
qr/0 \(proc1\) caused an error.+proc2/s,
is_deeply(
\@called,
[qw(proc1 proc1 proc2)],
"Continues on error"
);
# Override global for critical procs that must kill the pipeline if they die.
$oktorun = 1;
$pipeline = new Pipeline(continue_on_error=>1);
@called = ();
$pipeline->add(
name => 'proc1',
process => sub {
my ( $args ) = @_;
push @called, 'proc1';
$oktorun = 0 if @called > 8;
return $args;
},
);
$pipeline->add(
retry_on_error => 2,
name => 'proc2',
process => sub {
push @called, 'proc2';
die;
},
);
$output = output(
sub { $pipeline->execute(%args) },
stderr => 1,
);
is_deeply(
\@called,
[qw(proc1 proc2), # first attempt
qw(proc1 proc2), # retry 1/2
qw(proc1 proc2)], # retry 2/2
"Retry proc"
) or diag($output);
# #############################################################################
# Done.
# #############################################################################

View File

@@ -49,9 +49,9 @@ $output = output(
like(
$output,
qr/Query\s+1/,
"No infinite loop in report crashes (bug 888114)"
);
qr/Argument \S+ isn't numeric/,
"Report crashed, but no infinite loop (bug 888114)"
);
# #############################################################################
# Done.

View File

@@ -36,9 +36,6 @@ my $cmd;
my $pid_file = "/tmp/pt-query-digest-mirror-test.pid";
diag(`rm $pid_file 2>/dev/null`);
my $pid_file = '/tmp/pt-query-digest.test.pid';
`rm -rf $pid_file >/dev/null`;
# ##########################################################################
# Tests for swapping --processlist and --execute
# ##########################################################################