From 6614cae630def81baf1ac7f7ea108e2f42a8d334 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Thu, 7 Jun 2012 09:30:05 -0400 Subject: [PATCH] Make pt-table-sync/binlog_format.t stable. --- t/pt-table-sync/binlog_format.t | 41 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/t/pt-table-sync/binlog_format.t b/t/pt-table-sync/binlog_format.t index 7369f31f..3dc12079 100644 --- a/t/pt-table-sync/binlog_format.t +++ b/t/pt-table-sync/binlog_format.t @@ -10,6 +10,7 @@ use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); use Test::More; +use Data::Dumper; use PerconaTest; use Sandbox; @@ -29,37 +30,29 @@ elsif ( !$slave_dbh ) { plan skip_all => 'Cannot connect to sandbox slave'; } elsif ( !$vp->version_ge($master_dbh, '5.1.5') ) { - plan skip_all => 'Sandbox master version not >= 5.1'; + plan skip_all => 'Requires MySQL 5.1 or newer'; } else { plan tests => 7; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); -$sb->create_dbs($master_dbh, ['test']); - -my @args = qw(-F /tmp/12346/my.sandbox.cnf --sync-to-master P=12346 -t test.t); - # ############################################################################# # Issue 95: Make mk-table-sync force statement-based binlog format on 5.1 # ############################################################################# -$master_dbh->do('use test'); -$slave_dbh->do('use test'); - -$master_dbh->do('create table t (i int, unique index (i))'); -$master_dbh->do('insert into t values (1),(2)'); - -$slave_dbh->do('insert into t values (3)'); -PerconaTest::wait_for_table($slave_dbh, 'test.t', 'i=1'); +$sb->create_dbs($master_dbh, ['test']); +$master_dbh->do('create table test.t (i int, unique index (i))'); +$master_dbh->do('insert into test.t values (1),(2)'); +$sb->wait_for_slaves(); +$slave_dbh->do('insert into test.t values (3)'); # only on the slaves is_deeply( $master_dbh->selectall_arrayref('select * from test.t order by i'), [[1],[2]], 'Data on master before sync' ); -use Data::Dumper; + +# Slaves have an extra row, something to sync. my $rows = $slave_dbh->selectall_arrayref('select * from test.t order by i'); is_deeply( $rows, @@ -67,7 +60,7 @@ is_deeply( 'Data on slave before sync' ) or print Dumper($rows); -$master_dbh->do('SET GLOBAL binlog_format="ROW"'); +$master_dbh->do("SET GLOBAL binlog_format='ROW'"); $master_dbh->disconnect(); $master_dbh = $sb->get_dbh_for('master'); @@ -79,7 +72,8 @@ is_deeply( is( output( - sub { pt_table_sync::main(@args, qw(--print --execute)) }, + sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox", + qw(--sync-to-master -t test.t --print --execute)) }, trf => \&remove_traces, ), "DELETE FROM `test`.`t` WHERE `i`='3' LIMIT 1; @@ -87,14 +81,20 @@ is( "Executed DELETE" ); -sleep 1; +wait_until( + sub { + my $rows = $slave_dbh->selectall_arrayref('select * from test.t'); + return $rows && @$rows == 2; + } +) or die "DELETE did not replicate to slave"; + is_deeply( $slave_dbh->selectall_arrayref('select * from test.t'), [[1],[2]], 'DELETE replicated to slave' ); -$master_dbh->do('SET GLOBAL binlog_format="STATEMENT"'); +$master_dbh->do("SET GLOBAL binlog_format='STATEMENT'"); $master_dbh->disconnect(); $master_dbh = $sb->get_dbh_for('master'); @@ -108,6 +108,5 @@ is_deeply( # Done. # ############################################################################# $sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit;