From e5e6b1d9b9df5ee2a34422e756d798bf0cc8c7ba Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Fri, 8 Mar 2013 10:07:05 -0800 Subject: [PATCH] Fix pt-heartbeat/pxc.t. Exit early in test-env if wget fails. Add APP=FORK|mysql to start-sandbox so it too works around the pxc mysqld -V bug; add FORK=pxc to start_sandbox() calls. --- bin/pt-heartbeat | 2 +- lib/Sandbox.pm | 2 +- sandbox/jenkins-test | 3 +- sandbox/start-sandbox | 10 ++++-- t/pt-heartbeat/pxc.t | 63 ++++++++++++++++++--------------- t/pt-online-schema-change/pxc.t | 2 +- t/pt-table-checksum/pxc.t | 6 ++-- 7 files changed, 50 insertions(+), 38 deletions(-) diff --git a/bin/pt-heartbeat b/bin/pt-heartbeat index d3a25370..efe256c0 100755 --- a/bin/pt-heartbeat +++ b/bin/pt-heartbeat @@ -5395,7 +5395,7 @@ pt-heartbeat - Monitor MySQL replication delay. =head1 SYNOPSIS -Usage: pt-heartbeat [OPTION...] [DSN] --update|--monitor|--check|--stop +Usage: pt-heartbeat [OPTIONS] [DSN] --update|--monitor|--check|--stop pt-heartbeat measures replication lag on a MySQL or PostgreSQL server. You can use it to update a master or monitor a replica. If possible, MySQL connection diff --git a/lib/Sandbox.pm b/lib/Sandbox.pm index 263f38aa..f7371410 100644 --- a/lib/Sandbox.pm +++ b/lib/Sandbox.pm @@ -341,7 +341,7 @@ sub wait_for_slaves { sub { my ($pong) = $slave2_dbh->selectrow_array( "SELECT ping FROM percona_test.sentinel WHERE id=1 /* wait_for_slaves */"); - return $ping eq $pong; + return $ping eq ($pong || ''); }, undef, 300 ); } diff --git a/sandbox/jenkins-test b/sandbox/jenkins-test index a022938a..6dd71a77 100755 --- a/sandbox/jenkins-test +++ b/sandbox/jenkins-test @@ -61,7 +61,8 @@ fi if [ -z "$MYSQL_BASE_DIR" ]; then ( cd $MYSQL_BIN_DIR - wget -q -O mysql.tar.gz http://hackmysql.com/barebones/$APP/$MYSQL/$ARCH + wget -q -O mysql.tar.gz http://hackmysql.com/barebones/$APP/$MYSQL/$ARCH \ + || exit 1 tar xvfz mysql.tar.gz rm mysql.tar.gz ) diff --git a/sandbox/start-sandbox b/sandbox/start-sandbox index 1af01f20..7f34c0aa 100755 --- a/sandbox/start-sandbox +++ b/sandbox/start-sandbox @@ -223,12 +223,16 @@ elif [ -x "$PERCONA_TOOLKIT_SANDBOX/libexec/mysqld" ]; then else die "Cannot find executable mysqld in $PERCONA_TOOLKIT_SANDBOX/bin, $PERCONA_TOOLKIT_SANDBOX/sbin or $PERCONA_TOOLKIT_SANDBOX/libexec." fi -if [ $type != "cluster" ]; then - version=`$PERCONA_TOOLKIT_SANDBOX/$mysqld -V 2>/dev/null | awk '{print $3}' | cut -d. -f 1,2`; -else + +APP="${FORK:-"mysql"}" + +if [ $type = "cluster" -o $APP = "pxc" ]; then ip=$(perl -MNet::Address::IP::Local -le 'print Net::Address::IP::Local->public') version=`$PERCONA_TOOLKIT_SANDBOX/$mysqld -V --bind-address $ip 2>/dev/null | awk '{print $3}' | cut -d. -f 1,2`; +else + version=`$PERCONA_TOOLKIT_SANDBOX/$mysqld -V 2>/dev/null | awk '{print $3}' | cut -d. -f 1,2`; fi + if [ ! -d "$PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version" ]; then die "$PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version does not exist." fi diff --git a/t/pt-heartbeat/pxc.t b/t/pt-heartbeat/pxc.t index 0f6cc7b7..94082a5e 100644 --- a/t/pt-heartbeat/pxc.t +++ b/t/pt-heartbeat/pxc.t @@ -81,7 +81,7 @@ sub start_update_instance { exit 1; } push @exec_pids, $pid; - + PerconaTest::wait_for_files($pidfile); ok( -f $pidfile, @@ -235,11 +235,11 @@ my ($slave_dbh, $slave_dsn) = $sb->start_sandbox( server => 'cslave1', type => 'slave', master => 'node1', - env => q/BINLOG_FORMAT="ROW"/, + env => q/FORK="pxc" BINLOG_FORMAT="ROW"/, ); $sb->create_dbs($slave_dbh, ['test']); - +$sb->wait_for_slaves(master => 'node1', slave => 'cslave1'); start_update_instance($sb->port_for('cslave1')); PerconaTest::wait_for_table($slave_dbh, "test.heartbeat", "1=1"); @@ -292,31 +292,37 @@ like( my ($master_dbh, $master_dsn) = $sb->start_sandbox( server => 'cmaster', type => 'master', - env => q/BINLOG_FORMAT="ROW"/, + env => q/FORK="pxc" BINLOG_FORMAT="ROW"/, ); my $cmaster_port = $sb->port_for('cmaster'); $sb->create_dbs($master_dbh, ['test']); - +$master_dbh->do("INSERT INTO percona_test.sentinel (id, ping) VALUES (1, '')"); $master_dbh->do("FLUSH LOGS"); $master_dbh->do("RESET MASTER"); $sb->set_as_slave('node1', 'cmaster'); +$sb->wait_for_slaves(master => 'cmaster', slave => 'node1'); start_update_instance($sb->port_for('cmaster')); PerconaTest::wait_for_table($node1, "test.heartbeat", "server_id=$cmaster_port"); -$output = output(sub{ - pt_heartbeat::main($node1_dsn, qw(-D test --check --print-master-server-id)), - }, +# Auto-detecting the master id only works when ran on node1, the direct +# slave of the master, because other nodes aren't slaves, but this could +# be made to work; see the node autodiscovery branch. +$output = output( + sub { + pt_heartbeat::main($node1_dsn, + qw(-D test --check --print-master-server-id) + )}, stderr => 1, ); like( $output, qr/^\d.\d{2} $cmaster_port$/, - "--print-master-id works for master -> $node1_port, when run from $node1_port" + "Auto-detect master ID from node1" ); # Wait until node2 & node3 get cmaster in their heartbeat tables @@ -324,38 +330,39 @@ $sb->wait_for_slaves(master => 'node1', slave => 'node2'); $sb->wait_for_slaves(master => 'node1', slave => 'node3'); foreach my $test ( - [ $node2_port, $node2_dsn, $node2 ], - [ $node3_port, $node3_dsn, $node3 ], + [ $node2_port, $node2_dsn, $node2, 'node2' ], + [ $node3_port, $node3_dsn, $node3, 'node3' ], ) { - my ($port, $dsn, $dbh) = @$test; + my ($port, $dsn, $dbh, $name) = @$test; - $output = output(sub{ - pt_heartbeat::main($dsn, qw(-D test --check --print-master-server-id)), - }, + $output = output( + sub { + pt_heartbeat::main($dsn, + qw(-D test --check --print-master-server-id) + )}, stderr => 1, ); - # This could be made to work, see the node autodiscovery branch - TODO: { - local $::TODO = "cmaster -> node1, other nodes can't autodetect the master"; - like( - $output, - qr/$cmaster_port/, - "--print-master-id works for master -> $node1_port, when run from $port" - ); - } + like( + $output, + qr/server's master could not be automatically determined/, + "Limitation: cannot auto-detect master id from $name" + ); - $output = output(sub{ - pt_heartbeat::main($dsn, qw(-D test --check --master-server-id), $cmaster_port), - }, + $output = output( + sub { + pt_heartbeat::main($dsn, + qw(-D test --check --master-server-id), $cmaster_port + )}, stderr => 1, ); $output =~ s/\d\.\d{2}/0.00/g; + is( $output, "0.00\n", - "--check + explicit --master-server-id work for master -> node1, run from $port" + "$name --check --master-server-id $cmaster_port" ); } diff --git a/t/pt-online-schema-change/pxc.t b/t/pt-online-schema-change/pxc.t index dedeb400..c80ece7d 100644 --- a/t/pt-online-schema-change/pxc.t +++ b/t/pt-online-schema-change/pxc.t @@ -146,7 +146,7 @@ is_deeply( my ($master_dbh, $master_dsn) = $sb->start_sandbox( server => 'cmaster', type => 'master', - env => q/BINLOG_FORMAT="ROW"/, + env => q/FORK="pxc" BINLOG_FORMAT="ROW"/, ); $sb->set_as_slave('node1', 'cmaster'); diff --git a/t/pt-table-checksum/pxc.t b/t/pt-table-checksum/pxc.t index 3811208e..f8e01d4d 100644 --- a/t/pt-table-checksum/pxc.t +++ b/t/pt-table-checksum/pxc.t @@ -183,7 +183,7 @@ my ($slave_dbh, $slave_dsn) = $sb->start_sandbox( server => 'cslave1', type => 'slave', master => 'node1', - env => q/BINLOG_FORMAT="ROW"/, + env => q/FORK="pxc" BINLOG_FORMAT="ROW"/, ); # Add the slave to the DSN table. @@ -251,7 +251,7 @@ $sb->stop_sandbox('cslave1'); server => 'cslave1', type => 'slave', master => 'node2', - env => q/BINLOG_FORMAT="ROW"/, + env => q/FORK="pxc" BINLOG_FORMAT="ROW"/, ); # Wait for the slave to apply the binlogs from node2 (its master). @@ -300,7 +300,7 @@ $node1->do(qq/DELETE FROM dsns.dsns WHERE id=4/); my ($master_dbh, $master_dsn) = $sb->start_sandbox( server => 'cmaster', type => 'master', - env => q/BINLOG_FORMAT="ROW"/, + env => q/FORK="pxc" BINLOG_FORMAT="ROW"/, ); # Since master is new, node1 shouldn't have binlog to replay.