mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-07 21:09:14 +00:00
Fix sandbox/load-sakila-db so it exits on error.
This commit is contained in:
@@ -155,7 +155,7 @@ sub check_ids {
|
||||
# #############################################################################
|
||||
# Attempt to alter a table while another process is changing it.
|
||||
# #############################################################################
|
||||
sleep 2;
|
||||
|
||||
my $db_flavor = VersionParser->new($master_dbh)->flavor();
|
||||
if ( $db_flavor =~ m/XtraDB Cluster/ ) {
|
||||
$sb->load_file('master', "$sample/basic_no_fks_innodb.sql");
|
||||
|
@@ -25,8 +25,11 @@ sub test_func {
|
||||
die "No renamed_cols arg" unless $renamed_cols;
|
||||
(my $show_alter = $alter) =~ s/\n/\\n/g;
|
||||
|
||||
my %got_renamed_cols = eval {
|
||||
pt_online_schema_change::find_renamed_cols($alter, $tp);
|
||||
my $got_renamed_cols = eval {
|
||||
pt_online_schema_change::find_renamed_cols(
|
||||
alter => $alter,
|
||||
TableParser => $tp,
|
||||
);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
is_deeply(
|
||||
@@ -37,10 +40,10 @@ sub test_func {
|
||||
}
|
||||
else {
|
||||
is_deeply(
|
||||
\%got_renamed_cols,
|
||||
$got_renamed_cols,
|
||||
$renamed_cols,
|
||||
$show_alter,
|
||||
) or diag(Dumper(\%got_renamed_cols));
|
||||
) or diag(Dumper($got_renamed_cols));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,15 +212,13 @@ test_func(
|
||||
},
|
||||
);
|
||||
|
||||
TODO: {
|
||||
local $::TODO = "We don't parse the entire alter statement, what looks like a CHANGE COLUMNS";
|
||||
# Not really an alter, pathological
|
||||
test_func(
|
||||
"MODIFY `CHANGE a z VARCHAR(255) NOT NULL` FLOAT",
|
||||
{
|
||||
},
|
||||
);
|
||||
}
|
||||
# TODO
|
||||
## Not really an alter, pathological
|
||||
#test_func(
|
||||
# "MODIFY `CHANGE a z VARCHAR(255) NOT NULL` FLOAT",
|
||||
# {
|
||||
# },
|
||||
#);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
|
112
t/pt-online-schema-change/pxc.t
Normal file
112
t/pt-online-schema-change/pxc.t
Normal file
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
BEGIN {
|
||||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||
};
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
use Data::Dumper;
|
||||
|
||||
# Hostnames make testing less accurate. Tests need to see
|
||||
# that such-and-such happened on specific slave hosts, but
|
||||
# the sandbox servers are all on one host so all slaves have
|
||||
# the same hostname.
|
||||
$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
|
||||
require "$trunk/bin/pt-online-schema-change";
|
||||
# Do this after requiring ptc, since it uses Mo
|
||||
require VersionParser;
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $node1 = $sb->get_dbh_for('node1');
|
||||
my $node2 = $sb->get_dbh_for('node2');
|
||||
my $node3 = $sb->get_dbh_for('node3');
|
||||
|
||||
my $db_flavor = VersionParser->new($node1)->flavor();
|
||||
|
||||
if ( $db_flavor !~ /XtraDB Cluster/ ) {
|
||||
plan skip_all => "PXC tests";
|
||||
}
|
||||
elsif ( !$node1 ) {
|
||||
plan skip_all => 'Cannot connect to cluster node1';
|
||||
}
|
||||
elsif ( !$node2 ) {
|
||||
plan skip_all => 'Cannot connect to cluster node2';
|
||||
}
|
||||
elsif ( !$node3 ) {
|
||||
plan skip_all => 'Cannot connect to cluster node3';
|
||||
}
|
||||
|
||||
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
||||
# so we need to specify --lock-wait-timeout=3 else the tool will die.
|
||||
my $node1_dsn = $sb->dsn_for('node1');
|
||||
my @args = ($node1_dsn, qw(--lock-wait-timeout 3));
|
||||
my $output;
|
||||
my $exit;
|
||||
my $sample = "t/pt-online-schema-change/samples/";
|
||||
|
||||
# #############################################################################
|
||||
# Can't alter a MyISAM table.
|
||||
# #############################################################################
|
||||
|
||||
$sb->load_file('node1', "$sample/basic_no_fks.sql");
|
||||
|
||||
($output, $exit) = full_output(
|
||||
sub { pt_online_schema_change::main(
|
||||
"$node1_dsn,D=pt_osc,t=t",
|
||||
qw(--lock-wait-timeout 5),
|
||||
qw(--print --execute --alter ENGINE=InnoDB)) },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
ok(
|
||||
$exit,
|
||||
"Table is MyISAM: non-zero exit"
|
||||
) or diag($output);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/is a cluster node and the table is MyISAM/,
|
||||
"Table is MyISAM: error message"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Can't alter a table converted to MyISAM.
|
||||
# #############################################################################
|
||||
|
||||
$sb->load_file('node1', "$sample/basic_no_fks_innodb.sql");
|
||||
|
||||
($output, $exit) = full_output(
|
||||
sub { pt_online_schema_change::main(
|
||||
"$node1_dsn,D=pt_osc,t=t",
|
||||
qw(--lock-wait-timeout 5),
|
||||
qw(--print --execute --alter ENGINE=MyISAM)) },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
ok(
|
||||
$exit,
|
||||
"Convert table to MyISAM: non-zero exit"
|
||||
) or diag($output);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/is a cluster node and the table is being converted to MyISAM/,
|
||||
"Convert table to MyISAM: error message"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($node1);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
@@ -51,11 +51,10 @@ $sb->load_file('master', "$sample/data-loss-bug-1068562.sql");
|
||||
qw(--execute)) },
|
||||
);
|
||||
|
||||
is(
|
||||
ok(
|
||||
$exit_status,
|
||||
255,
|
||||
"Die if --execute without --no-check-alter"
|
||||
);
|
||||
) or diag($output);
|
||||
|
||||
like(
|
||||
$output,
|
||||
@@ -95,7 +94,7 @@ is(
|
||||
$exit_status,
|
||||
0,
|
||||
"sakila.city: Exit status 0",
|
||||
);
|
||||
) or diag($output);
|
||||
|
||||
my $mod = $master_dbh->selectall_arrayref(q{SELECT some_cities FROM sakila.city});
|
||||
|
||||
@@ -177,7 +176,7 @@ is(
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/first_name to first_name_mod, last_name to last_name_mod/ms,
|
||||
qr/first_name to first_name_mod.+?last_name to last_name_mod/ms,
|
||||
"--dry-run warns about renaming columns"
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user