From e93381d6b6648a79f6d4818ae626af4b1c412abd Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Tue, 23 Aug 2011 09:11:00 -0600 Subject: [PATCH] Make sandbox scripts simpler and more reliable. Remove "remove" option from stop-sandbox and update tests that used it. --- sandbox/start-sandbox | 17 +++------ sandbox/stop-sandbox | 56 ++++++------------------------ sandbox/test-env | 12 +++---- t/lib/DSNParser.t | 2 +- t/lib/MasterSlave.t | 6 ++-- t/lib/TableSyncer.t | 2 +- t/pt-heartbeat/multi_update_mode.t | 4 +-- t/pt-table-checksum/issue_69.t | 2 ++ t/pt-table-checksum/progress.t | 4 +-- t/pt-table-checksum/throttle.t | 4 +-- t/pt-table-sync/bidirectional.t | 4 +-- t/pt-table-sync/master_master.t | 2 +- t/pt-table-sync/replicate_do_db.t | 2 +- 13 files changed, 39 insertions(+), 78 deletions(-) diff --git a/sandbox/start-sandbox b/sandbox/start-sandbox index 9676ca6d..95ff7934 100755 --- a/sandbox/start-sandbox +++ b/sandbox/start-sandbox @@ -4,13 +4,9 @@ # It's a "low level" script that is not usually called directly. # Exit 0 means everything was successful, else exit 1 on problems. -err() { - echo - for msg; do - echo $msg - done - echo "See http://code.google.com/p/maatkit/wiki/Testing for more information." - echo +die() { + echo $1 >&2 + exit 1 } make_sandbox() { @@ -30,7 +26,7 @@ make_sandbox() { # Use ! instead of / because the replacment has / (it's a directory) sed -e "s!PERCONA_TOOLKIT_SANDBOX!$PERCONA_TOOLKIT_SANDBOX!g" -i.bak $file done - rm /tmp/$port/*.bak + rm /tmp/$port/*.bak >/dev/null 2>&1 if [ -n "$BINLOG_FORMAT" ]; then echo "binlog-format=$BINLOG_FORMAT" >> /tmp/$port/my.sandbox.cnf @@ -65,10 +61,7 @@ make_sandbox() { # Sanity check the cmd line options. # ########################################################################### if [ $# -lt 2 ]; then - err "Usage: start-sandbox master|slave|master-master port [master port]" \ - "Example: start-sandbox master 12345" \ - "Example: start-sandbox slave 12346 12345" - exit 1 + die "Usage: start-sandbox master|slave|master-master port [master port]" fi type=$1 # master, slave or master-master diff --git a/sandbox/stop-sandbox b/sandbox/stop-sandbox index d5b5ba88..e9a10c25 100755 --- a/sandbox/stop-sandbox +++ b/sandbox/stop-sandbox @@ -1,60 +1,26 @@ #!/bin/sh -err() { - echo - for msg; do - echo $msg - done - echo "See http://code.google.com/p/maatkit/wiki/Testing for more information." - echo +die() { + echo $1 >&2 + exit 1 } -# ########################################################################### -# Sanity check the cmd line options. -# ########################################################################### if [ $# -lt 1 ]; then - err "Usage: stop-sandbox [remove] all|port [port...]" \ - "The 'all' option stops sandboxes /tmp/123[0-9]*." \ - "The sandbox directories are removed if the first option is 'remove'." - exit 1 + die "Usage: stop-sandbox PORTS" fi -# ########################################################################### -# Stop the sandboxes. -# ########################################################################### - exit_status=0 -for port in $@; do - if [ "$port" = "remove" ]; then +for port in "$@"; do + if ! [ -d "/tmp/$port" ]; then + echo "MySQL test server on port $port does not exist." continue fi - if [ "$port" = "all" ]; then - ls /tmp/1234* >/dev/null 2>&1 - if [ $? -eq 0 ]; then - for a in /tmp/123[0-9]*; do - $a/stop - if [ $? -ne 0 ]; then - exit_status=1 - fi - if [ $1 = "remove" ]; then - rm -rf $a - fi - done - break - fi - fi - - if [ -d "/tmp/$port" ]; then - /tmp/$port/stop - if [ $? -ne 0 ]; then - exit_status=1 - fi - if [ $1 = "remove" ]; then - rm -rf /tmp/$port - fi - fi + /tmp/$port/stop + exit_status=$((exit_status | $?)) + rm -rf /tmp/$port + exit_status=$((exit_status | $?)) done exit $exit_status diff --git a/sandbox/test-env b/sandbox/test-env index 9eab7b8f..023d0427 100755 --- a/sandbox/test-env +++ b/sandbox/test-env @@ -309,21 +309,19 @@ case $opt in set_mysql_version echo "Percona Toolkit test environment started with MySQL v$MYSQL_VERSION." else - # Stop but don't remove the sandboxes. The mysql error log - # may say why MySQL failed to start. - ./stop-sandbox all >/dev/null 2>&1 err "There was an error starting the Percona Toolkit test environment." fi ;; stop) cd $PERCONA_TOOLKIT_BRANCH/sandbox - ./stop-sandbox remove all - exit_status=$? + ./stop-sandbox 12349 12348 12347 12346 12345 + exit_status=$((exit_status | $?)) + ./stop-sandbox 2903 2902 2901 2900 + exit_status=$((exit_status | $?)) if [ $exit_status -eq 0 ]; then echo "Percona Toolkit test environment stopped." else - err "There was an error stopping the Percona Toolkit test environment." \ - "The MySQL test servers may still be running." + err "Error stopping the Percona Toolkit test environment." fi ;; kill) diff --git a/t/lib/DSNParser.t b/t/lib/DSNParser.t index 60884270..301fb8c0 100644 --- a/t/lib/DSNParser.t +++ b/t/lib/DSNParser.t @@ -457,7 +457,7 @@ SKIP: { ); $dbh->disconnect(); - diag(`$trunk/sandbox/stop-sandbox remove 12348 >/dev/null`); + diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`); }; # ############################################################################# diff --git a/t/lib/MasterSlave.t b/t/lib/MasterSlave.t index be964cdc..a29e845b 100644 --- a/t/lib/MasterSlave.t +++ b/t/lib/MasterSlave.t @@ -40,7 +40,9 @@ my %port_for = ( slave2 => 2903, ); foreach my $port ( values %port_for ) { - diag(`$trunk/sandbox/stop-sandbox remove $port >/dev/null`); + if ( -d "/tmp/$port" ) { + diag(`$trunk/sandbox/stop-sandbox $port >/dev/null`); + } } diag(`$trunk/sandbox/start-sandbox master 2900 >/dev/null`); diag(`$trunk/sandbox/start-sandbox slave 2903 2900 >/dev/null`); @@ -464,5 +466,5 @@ ok( # ############################################################################# # Done. # ############################################################################# -diag(`$trunk/sandbox/stop-sandbox remove 2903 2902 2901 2900 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 2903 2902 2901 2900 >/dev/null`); exit; diff --git a/t/lib/TableSyncer.t b/t/lib/TableSyncer.t index 671826b3..63d3295d 100644 --- a/t/lib/TableSyncer.t +++ b/t/lib/TableSyncer.t @@ -946,7 +946,7 @@ SKIP: { ); $sb->wipe_clean($dbh2); - diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null &`); + diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null &`); } } diff --git a/t/pt-heartbeat/multi_update_mode.t b/t/pt-heartbeat/multi_update_mode.t index 3eb4411b..06ac02d7 100644 --- a/t/pt-heartbeat/multi_update_mode.t +++ b/t/pt-heartbeat/multi_update_mode.t @@ -17,7 +17,7 @@ use Sandbox; require "$trunk/bin/pt-heartbeat"; diag(`$trunk/sandbox/test-env reset`); # don't repl sakila db to 12347 -diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`); diag(`$trunk/sandbox/start-sandbox slave 12347 12346 >/dev/null`); my $dp = new DSNParser(opts=>$dsn_opts); @@ -247,7 +247,7 @@ foreach my $port (@ports) { } diag(`rm -rf /tmp/mk-heartbeat-sentinel >/dev/null`); -diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`); # ############################################################################# # Done. diff --git a/t/pt-table-checksum/issue_69.t b/t/pt-table-checksum/issue_69.t index 006b99d4..24f52612 100644 --- a/t/pt-table-checksum/issue_69.t +++ b/t/pt-table-checksum/issue_69.t @@ -30,6 +30,8 @@ else { plan tests => 2; } +`$trunk/sandbox/test-env reset >/dev/null`; + my $output; my $cnf='/tmp/12345/my.sandbox.cnf'; my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1"; diff --git a/t/pt-table-checksum/progress.t b/t/pt-table-checksum/progress.t index ec83566f..10a122b6 100644 --- a/t/pt-table-checksum/progress.t +++ b/t/pt-table-checksum/progress.t @@ -16,7 +16,7 @@ use Sandbox; require "$trunk/bin/pt-table-checksum"; diag(`$trunk/sandbox/test-env reset`); -diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`); diag(`$trunk/sandbox/start-sandbox slave 12347 12346 >/dev/null`); my $dp = new DSNParser(opts=>$dsn_opts); @@ -94,7 +94,7 @@ like( # ############################################################################# # Done. # ############################################################################# -diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`); diag(`/tmp/12346/stop >/dev/null`); # Start/stop clears SHOW SLAVE HOSTS. diag(`/tmp/12346/start >/dev/null`); $sb->wipe_clean($master_dbh); diff --git a/t/pt-table-checksum/throttle.t b/t/pt-table-checksum/throttle.t index a2501f90..0cbc568b 100644 --- a/t/pt-table-checksum/throttle.t +++ b/t/pt-table-checksum/throttle.t @@ -16,7 +16,7 @@ use Sandbox; require "$trunk/bin/pt-table-checksum"; diag(`$trunk/sandbox/test-env reset`); -diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`); diag(`$trunk/sandbox/start-sandbox slave 12347 12346 >/dev/null`); my $dp = new DSNParser(opts=>$dsn_opts); @@ -280,7 +280,7 @@ is( # ############################################################################# # Done. # ############################################################################# -diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`); $sb->wipe_clean($master_dbh); diag(`$trunk/sandbox/test-env reset >/dev/null`); exit; diff --git a/t/pt-table-sync/bidirectional.t b/t/pt-table-sync/bidirectional.t index 118102b1..2112c6b0 100644 --- a/t/pt-table-sync/bidirectional.t +++ b/t/pt-table-sync/bidirectional.t @@ -534,7 +534,7 @@ SKIP: { # ############################################################################# # Done. # ############################################################################# -diag(`$trunk/sandbox/stop-sandbox remove 12347 >/dev/null &`); -diag(`$trunk/sandbox/stop-sandbox remove 12348 >/dev/null &`); +diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`); $sb->wipe_clean($c1_dbh); exit; diff --git a/t/pt-table-sync/master_master.t b/t/pt-table-sync/master_master.t index 5188553d..f1b8f2f6 100644 --- a/t/pt-table-sync/master_master.t +++ b/t/pt-table-sync/master_master.t @@ -39,7 +39,7 @@ SKIP: { $output = `/tmp/12348/use -e 'select b from test.test1 where a=1' -N`; like($output, qr/mm/, 'Master-master sync worked'); - diag(`$trunk/sandbox/stop-sandbox remove 12348 12349 >/dev/null`); + diag(`$trunk/sandbox/stop-sandbox 12348 12349 >/dev/null`); }; # ############################################################################# diff --git a/t/pt-table-sync/replicate_do_db.t b/t/pt-table-sync/replicate_do_db.t index 3b51d704..6bdf9730 100644 --- a/t/pt-table-sync/replicate_do_db.t +++ b/t/pt-table-sync/replicate_do_db.t @@ -121,7 +121,7 @@ is_deeply( ); $dbh3->disconnect(); -diag(`$trunk/sandbox/stop-sandbox remove 12348 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`); # ############################################################################# # Done.