~percona-toolkit-dev/percona-toolkit/mysql-5.6-test-fixes

« back to all changes in this revision

Viewing changes to t/pt-table-checksum/progress.t

  • Committer: Daniel Nichter
  • Date: 2011-10-14 17:45:11 UTC
  • mto: (106.3.109 pt-table-checksum-2.0)
  • mto: This revision was merged to the branch mainline in revision 121.
  • Revision ID: daniel@percona.com-20111014174511-kosne4jww2l7evrq
Update progress.t, option_sanity.t, and standard_options.t.  Make test env always have slave2 (12347, slave of 12346).  Add PerconaTest::count_checksum_results().  Add util/wait-to-exec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
use Sandbox;
16
16
require "$trunk/bin/pt-table-checksum";
17
17
 
18
 
diag(`$trunk/sandbox/test-env reset`);
19
 
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
20
 
diag(`$trunk/sandbox/start-sandbox slave 12347 12346 >/dev/null`);
21
 
 
22
18
my $dp = new DSNParser(opts=>$dsn_opts);
23
19
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
24
20
my $master_dbh = $sb->get_dbh_for('master');
38
34
   plan tests => 3;
39
35
}
40
36
 
 
37
# Must have empty checksums table for these tests.
 
38
$master_dbh->do('drop table if exists percona.checksums');
 
39
 
 
40
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
 
41
# so we need to specify --lock-wait-timeout=3 else the tool will die.
 
42
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
 
43
my @args       = ($master_dsn, qw(--lock-wait-timeout 3),
 
44
                  '--progress', 'time,1'); 
41
45
my $output;
42
46
my $row;
43
 
my $cnf  ='/tmp/12345/my.sandbox.cnf';
44
 
my @args = (qw(--replicate test.checksum  --empty-replicate-table -d test -t resume -q), '-F', $cnf, 'h=127.1', '--progress', 'time,1');
45
 
 
46
 
$sb->create_dbs($master_dbh, [qw(test)]);
47
 
$sb->load_file('master', 't/pt-table-checksum/samples/checksum_tbl.sql');
48
 
# We're not using resume table for anything specific, we just need
49
 
# any table to checksum.
50
 
$sb->load_file('master', 't/pt-table-checksum/samples/resume.sql');
51
 
 
 
47
my $scripts = "$trunk/t/pt-table-checksum/scripts/";
 
48
 
 
49
# ############################################################################
 
50
# Tool should check all slaves' lag, so slave2, not just slave1.
 
51
# ############################################################################
52
52
wait_until(  # slaves aren't lagging
53
53
   sub {
54
54
      $row = $slave1_dbh->selectrow_hashref('show slave status');
56
56
      $row = $slave2_dbh->selectrow_hashref('show slave status');
57
57
      return 0 if $row->{Seconds_Behind_Master};
58
58
      return 1;
59
 
   }, 0.5, 10);
60
 
 
61
 
$slave1_dbh->do('stop slave sql_thread');
62
 
$row = $slave1_dbh->selectrow_hashref('show slave status');
63
 
is(
64
 
   $row->{slave_sql_running},
65
 
   'No',
66
 
   'Stopped slave SQL thread on slave1'
67
 
);
68
 
 
69
 
$slave2_dbh->do('stop slave sql_thread');
70
 
$row = $slave2_dbh->selectrow_hashref('show slave status');
71
 
is(
72
 
   $row->{slave_sql_running},
73
 
   'No',
74
 
   'Stopped slave SQL thread on slave2'
75
 
);
76
 
 
77
 
system("sleep 2 && /tmp/12346/use -e 'start slave sql_thread' >/dev/null 2>/dev/null &");
78
 
system("sleep 3 && /tmp/12347/use -e 'start slave sql_thread' >/dev/null 2>/dev/null &");
79
 
 
80
 
# This time we do not need to capture STDERR because mk-table-checksum
81
 
# should see slave2 come alive in 2 seconds then return before wait_for
82
 
# dies.
 
59
   }
 
60
) or die "Slaves are still lagging";
 
61
 
 
62
# This big fancy command waits until it sees the checksum for sakila.city
 
63
# in the repl table on the master, then it stops slave2 for 2 seconds,
 
64
# then starts it again.
 
65
system("$trunk/util/wait-to-exec '$scripts/wait-for-chunk.sh 12345 sakila city 1' '$scripts/exec-wait-exec.sh 12347 \"stop slave sql_thread\" 2 \"start slave sql_thread\"' 3 >/dev/null &");
 
66
 
83
67
$output = output(
84
 
   sub { pt_table_checksum::main(@args); },
 
68
   sub { pt_table_checksum::main(@args, qw(-d sakila)); },
85
69
   stderr => 1,
86
70
);
87
71
 
88
72
like(
89
73
   $output,
90
 
   qr/Waiting for slave.+?Still waiting/s,
91
 
   "Progress reports while waiting for slaves"
 
74
   qr/Replica h=127.0.0.1,P=12347 is stopped/,
 
75
   "--progress for slave lag"
 
76
);
 
77
 
 
78
like(
 
79
   $output,
 
80
   qr/sakila.store$/m,
 
81
   "Checksumming continues after waiting for slave lag"
 
82
);
 
83
 
 
84
is(
 
85
   PerconaTest::count_checksum_results($output, 'errors'),
 
86
   0,
 
87
   "No errors after waiting for slave lag"
92
88
);
93
89
 
94
90
# #############################################################################
95
91
# Done.
96
92
# #############################################################################
97
 
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
98
 
diag(`/tmp/12346/stop >/dev/null`);  # Start/stop clears SHOW SLAVE HOSTS.
99
 
diag(`/tmp/12346/start >/dev/null`);
100
93
$sb->wipe_clean($master_dbh);
101
94
diag(`$trunk/sandbox/test-env reset >/dev/null`);
102
95
exit;