diff --git a/Changelog b/Changelog index d08d58f..db6379e 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +3.1.04 07-Dec-2015 + - Fixed wrong version comparison (affects usage of MySQL 5.7.10) + - Changed tests to use smarter version comparison 3.1.03 04-Dec-2015 - Increased timeout for 'start' script, needed when restart requires a longer time. diff --git a/bin/low_level_make_sandbox b/bin/low_level_make_sandbox index 6738d98..8c98ddc 100755 --- a/bin/low_level_make_sandbox +++ b/bin/low_level_make_sandbox @@ -20,7 +20,7 @@ use warnings; use English qw( -no_match_vars ); use Data::Dumper; use Getopt::Long qw(:config no_ignore_case ); -use MySQL::Sandbox qw( find_safe_port_and_directory exists_in_path runs_as_root use_env sbinstr fix_server_uuid); +use MySQL::Sandbox qw( find_safe_port_and_directory exists_in_path runs_as_root use_env sbinstr fix_server_uuid greater_version split_version); use MySQL::Sandbox::Scripts; my $DEBUG = $MySQL::Sandbox::DEBUG; @@ -630,23 +630,13 @@ if ($msb->{options}{datadir_from} eq 'script' ) { if ($mysql_version) { chomp $mysql_version; - my ($major, $minor, $rev) ; - if ($mysql_version =~ /^(\d+)\.(\d+)\.(\d+)/ ) - { - $major = $1; - $minor=$2; - $rev = $3; - } - else - { - die "Can't get version components numbers from <$mysql_version>\n"; - } + my ($major, $minor, $rev) = split_version($mysql_version); $mysql_version=sprintf('%d.%d.%d', $major,$minor, $rev); - if ($mysql_version eq '5.7.5' ) + if (greater_version($mysql_version, '5.7.5' ) && ($major < 10) ) { $additional_options .= ' --insecure' ; } - elsif (($mysql_version ge '5.7.6' ) && ($major < 10)) # exclude MariaDB from this feature + elsif ((greater_version($mysql_version, '5.7.6') ) && ($major < 10)) # exclude MariaDB from this feature { # mysql_install_db is deprecated. It is now replaced by 'mysqld --initialize' # https://dev.mysql.com/doc/refman/5.7/en/mysql-install-db.html diff --git a/bin/test_sandbox b/bin/test_sandbox index 53778a6..952e725 100755 --- a/bin/test_sandbox +++ b/bin/test_sandbox @@ -19,7 +19,7 @@ use strict; use warnings; use Data::Dumper; use Getopt::Long qw(:config no_ignore_case ); -use MySQL::Sandbox qw(use_env); +use MySQL::Sandbox qw(use_env greater_version); use English qw( -no_match_vars ); use Carp; @@ -1185,14 +1185,13 @@ sub run_smoke_test { expected => '^0$', msg => "tables in install_test " }); - $sql_result = get_sql_result( "$sandbox_home/msb_$version", q{ drop database install_test;}, $verbose); my $sandbox_dirs = how_many_dirs("$sandbox_home/msb_$version/data"); my $expected_dirs = 2; - if ($bare_version ge '5.7.7') + if (greater_version( $bare_version, '5.7.7') && ( $bare_version !~ /^10/)) { $expected_dirs = 4; } diff --git a/lib/MySQL/Sandbox.pm b/lib/MySQL/Sandbox.pm index e71c300..b97ea4b 100644 --- a/lib/MySQL/Sandbox.pm +++ b/lib/MySQL/Sandbox.pm @@ -26,9 +26,11 @@ our @EXPORT_OK= qw( is_port_open get_option_file_contents validate_json_object fix_server_uuid + greater_version + split_version ) ; -our $VERSION="3.1.03"; +our $VERSION="3.1.04"; our $DEBUG; BEGIN { @@ -238,6 +240,41 @@ sub credits { return $CREDITS; } +sub split_version +{ + my ($v) = @_; + if ($v =~ /(\d+)\.(\d+)\.(\d+)/ ) + { + return ($1, $2, $3) + } + else + { + die "# Split version: could not get components from <$v>\n"; + } +} + +sub greater_version +{ + my ($v1, $v2) = @_; + + my ($v1_major, $v1_minor, $v1_rev) = split_version($v1); + my ($v2_major, $v2_minor, $v2_rev) = split_version($v2); + if ( $v1_major > $v2_major) + { + return 1; + } + elsif ( ($v1_major == $v2_major) && ($v1_minor > $v2_minor)) + { + return 1; + } + elsif ( ($v1_major == $v2_major) && ($v1_minor == $v2_minor) && ($v1_rev > $v2_rev) ) + { + return 1; + } + return 0 +} + + sub fix_server_uuid { my ($server_id, $version, $port, $sandbox_directory) = @_; diff --git a/lib/MySQL/Sandbox/Recipes.pm b/lib/MySQL/Sandbox/Recipes.pm index 60d4f2b..575d235 100644 --- a/lib/MySQL/Sandbox/Recipes.pm +++ b/lib/MySQL/Sandbox/Recipes.pm @@ -1,6 +1,6 @@ package MySQL::Sandbox::Recipes; -our $VERSION="3.1.03"; +our $VERSION="3.1.04"; 1; __END__ diff --git a/lib/MySQL/Sandbox/Scripts.pm b/lib/MySQL/Sandbox/Scripts.pm index c11b21b..4d51d5a 100644 --- a/lib/MySQL/Sandbox/Scripts.pm +++ b/lib/MySQL/Sandbox/Scripts.pm @@ -17,7 +17,7 @@ our @EXPORT_OK = qw( ); our @EXPORT = @EXPORT_OK; -our $VERSION="3.1.03"; +our $VERSION="3.1.04"; our @MANIFEST = ( 'clear.sh', diff --git a/t/Test_Helper.pm b/t/Test_Helper.pm index e45eea2..a77d54f 100644 --- a/t/Test_Helper.pm +++ b/t/Test_Helper.pm @@ -12,7 +12,7 @@ BEGIN { if ($^O =~ /^(?:mswin|win)/i) { skip_all ('This module is not for Windows'); } - use MySQL::Sandbox; + use MySQL::Sandbox qw/split_version/; $ENV{TEST_SANDBOX_HOME}="$ENV{PWD}/t/test_sb"; $ENV{PERL5LIB}="$ENV{PWD}/lib"; $ENV{PATH}="$ENV{PWD}/bin:$ENV{PATH}"; @@ -28,27 +28,27 @@ our @ISA= qw(Exporter); our @EXPORT_OK= qw( test_sandbox find_plugindir skip_all confirm_version); our @EXPORT = @EXPORT_OK; -sub get_version_parts -{ - my ($version) = @_; - if ($version =~ /(\d+)\.(\d+)\.(\d+)/) - { - my ($major, $minor, $rev) = ($1, $2, $3) ; - return ($major, $minor, $rev); - } - else - { - die "# version $version does not have expected components" - } -} +#sub get_version_parts +#{ +# my ($version) = @_; +# if ($version =~ /(\d+)\.(\d+)\.(\d+)/) +# { +# my ($major, $minor, $rev) = ($1, $2, $3) ; +# return ($major, $minor, $rev); +# } +# else +# { +# die "# version $version does not have expected components" +# } +#} sub confirm_version { my ($min_version, $max_version) = @_; my $will_skip =0; - my ($major, $minor, $rev) = get_version_parts($test_version); - my ($major1, $minor1, $rev1) = get_version_parts($min_version); - my ($major2, $minor2, $rev2) = get_version_parts($max_version); + my ($major, $minor, $rev) = split_version($test_version); + my ($major1, $minor1, $rev1) = split_version($min_version); + my ($major2, $minor2, $rev2) = split_version($max_version); my $compare_test = sprintf("%05d-%05d-%05d", $major, $minor, $rev); my $compare_min = sprintf("%05d-%05d-%05d", $major1, $minor1, $rev1); my $compare_max = sprintf("%05d-%05d-%05d", $major2, $minor2, $rev2); @@ -100,6 +100,24 @@ sub test_sandbox { sub find_plugindir { my ($minimum_version, $maximum_version, $use_current) = @_; + my $minimum_version_str; + my $maximum_version_str; + if ($minimum_version =~ /(\d+)\.(\d+)\.(\d+)/) + { + $minimum_version_str = sprintf('%02d-%02d-%02d', $1, $2, $3); + } + else + { + die "# Invalid minimum version provided : $minimum_version\n"; + } + if ($maximum_version =~ /(\d+)\.(\d+)\.(\d+)/) + { + $maximum_version_str = sprintf('%02d-%02d-%02d', $1, $2, $3); + } + else + { + die "# Invalid maximum version provided : $maximum_version\n"; + } my $plugindir; if ( @@ -114,8 +132,8 @@ sub find_plugindir { my $highest_version = ''; my @versions = (); my @dirs = sort { $b cmp $a } - grep { ($_ ge $minimum_version) && ($_ le $maximum_version) } - map { m{(\d\.\d\.\d+)/?$}; $1 } + grep { ($_ ge $minimum_version_str) && ($_ le $maximum_version_str) } + map { m{(\d)\.(\d)\.(\d+)/?$}; sprintf('%02d-%02d-%02d',$1,$2,$3) } grep { /\d+\.\d+\.\d+/ } grep { -d $_ } glob("$ENV{SANDBOX_BINARY}/*/" ) ; @@ -123,7 +141,7 @@ sub find_plugindir { skip_all("no directories found under $ENV{SANDBOX_BINARY}"); } $highest_version = $dirs[0]; - if ($highest_version lt $minimum_version) { + if ($highest_version lt $minimum_version_str) { skip_all("no suitable version found for this test"); } my $TEST_VERSION = $ENV{TEST_VERSION} || $highest_version;