~percona-toolkit-dev/percona-toolkit/manual-for-pt-query-digest--type-binlog-is-ambiguous-1377888

« back to all changes in this revision

Viewing changes to t/pt-online-schema-change/bug-1315130.t

  • Committer: Frank Cizmich
  • Date: 2014-07-29 15:51:01 UTC
  • mfrom: (606.1.12 release-2.2.9)
  • Revision ID: frank.cizmich@percona.com-20140729155101-f5kv4rmeu3s5rzk5
mergedĀ releaseĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
 
 
3
BEGIN {
 
4
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
 
5
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
 
6
   unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
 
7
};
 
8
 
 
9
use strict;
 
10
use warnings FATAL => 'all';
 
11
use English qw(-no_match_vars);
 
12
use Test::More;
 
13
use Time::HiRes qw(sleep);
 
14
 
 
15
$ENV{PTTEST_FAKE_TS} = 1;
 
16
$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
 
17
 
 
18
use PerconaTest;
 
19
use Sandbox;
 
20
require "$trunk/bin/pt-online-schema-change";
 
21
require VersionParser;
 
22
 
 
23
use Data::Dumper;
 
24
$Data::Dumper::Indent    = 1;
 
25
$Data::Dumper::Sortkeys  = 1;
 
26
$Data::Dumper::Quotekeys = 0;
 
27
 
 
28
my $dp         = new DSNParser(opts=>$dsn_opts);
 
29
my $sb         = new Sandbox(basedir => '/tmp', DSNParser => $dp);
 
30
my $master_dbh = $sb->get_dbh_for('master');
 
31
my $slave_dbh  = $sb->get_dbh_for('slave1');
 
32
 
 
33
if ( !$master_dbh ) {
 
34
   plan skip_all => 'Cannot connect to sandbox master';
 
35
}
 
36
elsif ( !$slave_dbh ) {
 
37
   plan skip_all => 'Cannot connect to sandbox slave';
 
38
}
 
39
 
 
40
my $q      = new Quoter();
 
41
my $tp     = new TableParser(Quoter => $q);
 
42
my @args   = qw(--set-vars innodb_lock_wait_timeout=3);
 
43
my $output = "";
 
44
my $dsn    = "h=127.1,P=12345,u=msandbox,p=msandbox";
 
45
my $exit   = 0;
 
46
my $sample = "t/pt-online-schema-change/samples";
 
47
my $rows;
 
48
 
 
49
 
 
50
# #############################################################################
 
51
# Issue 1315130
 
52
# Failed to detect child tables in other schema, and falsely identified
 
53
# child tables in own schema
 
54
# #############################################################################
 
55
 
 
56
$sb->load_file('master', "$sample/bug-1315130_cleanup.sql");
 
57
$sb->load_file('master', "$sample/bug-1315130.sql");
 
58
($output, $exit) = full_output(
 
59
   sub { pt_online_schema_change::main(@args, "$dsn,D=bug_1315130_a,t=parent_table",
 
60
         '--dry-run', 
 
61
         '--alter', "add column c varchar(16)",
 
62
         '--alter-foreign-keys-method', 'auto'),
 
63
      },
 
64
);
 
65
print STDERR "[$output]\n";
 
66
   like(
 
67
         $output,
 
68
         qr/Child tables:\s*`bug_1315130_a`\.`child_table_in_same_schema` \(approx\. 1 rows\)\s*`bug_1315130_b`\.`child_table_in_second_schema` \(approx\. 1 rows\)[^`]*?Will/s,
 
69
         "Correctly identify child tables from other schemas and ignores tables from same schema referencig same named parent in other schema.",
 
70
   );
 
71
# clear databases with their foreign keys
 
72
$sb->load_file('master', "$sample/bug-1315130_cleanup.sql");  
 
73
 
 
74
# Done.
 
75
# #############################################################################
 
76
$sb->wipe_clean($master_dbh);
 
77
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
 
78
done_testing;