diff --git a/lib/MasterSlave.pm b/lib/MasterSlave.pm index 47dab9ae..9c1083be 100644 --- a/lib/MasterSlave.pm +++ b/lib/MasterSlave.pm @@ -32,8 +32,18 @@ use constant PTDEBUG => $ENV{PTDEBUG} || 0; sub check_recursion_method { my ($methods) = @_; - if ( @$methods != 1 ) { - if ( grep({ !m/processlist|hosts/i } @$methods) + # Check that each method is valid. + foreach my $method ( @$methods ) { + die "Invalid recursion method: " . ($method || 'undef') . "\n" + unless $method && $method =~ m/^(?:processlist$|hosts$|none$|cluster|dsn=)/i; + } + + # Check for invalid combination of methods. + if ( @$methods > 1 ) { + if ( grep( { m/none/ } @$methods) && grep( {! m/none/ } @$methods) ) { + die "--recursion-method=none cannot be combined with other methods\n"; + } + elsif ( grep({ !m/processlist|hosts/i } @$methods) && $methods->[0] !~ /^dsn=/i ) { die "Invalid combination of recursion methods: " @@ -41,11 +51,8 @@ sub check_recursion_method { . "Only hosts and processlist may be combined.\n" } } - else { - my ($method) = @$methods; - die "Invalid recursion method: " . ( $method || 'undef' ) - unless $method && $method =~ m/^(?:processlist$|hosts$|none$|dsn=)/i; - } + + return; } sub new { diff --git a/t/lib/MasterSlave.t b/t/lib/MasterSlave.t index ad14fa6a..68c2647b 100644 --- a/t/lib/MasterSlave.t +++ b/t/lib/MasterSlave.t @@ -11,10 +11,6 @@ use warnings FATAL => 'all'; use English qw(-no_match_vars); use Test::More; -if ( !$ENV{SLOW_TESTS} ) { - plan skip_all => "lib/MasterSlave.t is a top 5 slowest file; set SLOW_TESTS=1 to enable it."; -} - use MasterSlave; use DSNParser; use VersionParser; @@ -709,28 +705,51 @@ is( # ############################################################################ # Invalid recursion methods are caught # ############################################################################ -local $EVAL_ERROR; eval { MasterSlave::check_recursion_method([qw(stuff)]) }; - like( $EVAL_ERROR, qr/Invalid recursion method: stuff/, "--recursion-method stuff causes error" ); -local $EVAL_ERROR; eval { MasterSlave::check_recursion_method([qw(processlist stuff)]) }; - like( $EVAL_ERROR, - qr/Invalid combination of recursion methods: processlist, stuff/, + qr/Invalid recursion method: stuff/, "--recursion-method processlist,stuff causes error", ); +eval { + MasterSlave::check_recursion_method([qw(none hosts)]) +}; +like( + $EVAL_ERROR, + qr/none cannot be combined with other methods/, + "--recursion-method none,hosts" +); + +eval { + MasterSlave::check_recursion_method([qw(cluster none)]) +}; +like( + $EVAL_ERROR, + qr/none cannot be combined with other methods/, + "--recursion-method cluster,none" +); + +eval { + MasterSlave::check_recursion_method([qw(none none)]) +}; +like( + $EVAL_ERROR, + qr/Invalid combination of recursion methods: none, none/, + "--recursion-method none,none" +); + # ############################################################################# # Done. # #############################################################################