Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Fixed wrong version comparison
Browse files Browse the repository at this point in the history
(affects usage of MySQL 5.7.10)
Changed tests to use smarter version comparison
  • Loading branch information
datacharmer committed Dec 8, 2015
1 parent 0550310 commit ebd4ec6
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 40 deletions.
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 4 additions & 14 deletions bin/low_level_make_sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions bin/test_sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
39 changes: 38 additions & 1 deletion lib/MySQL/Sandbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/MySQL/Sandbox/Recipes.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package MySQL::Sandbox::Recipes;

our $VERSION="3.1.03";
our $VERSION="3.1.04";

1;
__END__
Expand Down
2 changes: 1 addition & 1 deletion lib/MySQL/Sandbox/Scripts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
58 changes: 38 additions & 20 deletions t/Test_Helper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand All @@ -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);
Expand Down Expand Up @@ -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 (
Expand All @@ -114,16 +132,16 @@ 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}/*/" ) ;
unless (@dirs) {
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;
Expand Down

0 comments on commit ebd4ec6

Please sign in to comment.