diff options
Diffstat (limited to 'mysql-test/include')
-rw-r--r-- | mysql-test/include/master-slave-end.inc | 6 | ||||
-rw-r--r-- | mysql-test/include/ndb_backup.inc | 43 | ||||
-rw-r--r-- | mysql-test/include/start_slave.inc | 21 | ||||
-rw-r--r-- | mysql-test/include/stop_slave.inc | 21 | ||||
-rw-r--r-- | mysql-test/include/wait_for_slave_sql_error.inc | 40 | ||||
-rw-r--r-- | mysql-test/include/wait_for_slave_sql_error_and_skip.inc | 39 | ||||
-rw-r--r-- | mysql-test/include/wait_show_condition.inc | 78 | ||||
-rw-r--r-- | mysql-test/include/wait_until_count_sessions.inc | 36 |
8 files changed, 265 insertions, 19 deletions
diff --git a/mysql-test/include/master-slave-end.inc b/mysql-test/include/master-slave-end.inc new file mode 100644 index 00000000000..74e4c7b608a --- /dev/null +++ b/mysql-test/include/master-slave-end.inc @@ -0,0 +1,6 @@ +--connection master +--sync_slave_with_master +--connection slave +--disable_query_log +STOP SLAVE; +--enable_query_log diff --git a/mysql-test/include/ndb_backup.inc b/mysql-test/include/ndb_backup.inc index f0a883d4e11..752155a8dbd 100644 --- a/mysql-test/include/ndb_backup.inc +++ b/mysql-test/include/ndb_backup.inc @@ -2,23 +2,50 @@ # By JBM 2006-02-16 So that the code is not repeated # # in test cases and can be reused. # ###################################################### ---exec $NDB_MGM --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -e "start backup" >> $NDB_TOOLS_OUTPUT - -# there is no neat way to find the backupid, this is a hack to find it... ---exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $MYSQLTEST_VARDIR/tmp.dat +--exec $NDB_MGM --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -e "start backup" >> $NDB_TOOLS_OUTPUT -CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP; +# To find the backupid, we must dump this data to a table, and SELECT +# what we want into an outfile. This could be accomplished with grep, but +# grep isn't Windows-portable + +--disable_query_log +# create a table to help us out +--disable_warnings # leave this on until done with the entire process +# cleanup +DROP TABLE IF EXISTS helper1; +CREATE TABLE helper1(c1 VARCHAR(20)); +# dump raw data to file +let $ndb_backup_file1= $MYSQLTEST_VARDIR/ndb_backup_tmp.dat; +let $ndb_backup_file2= $MYSQLTEST_VARDIR/tmp.dat; +--error 0,1 +--remove_file $ndb_backup_file1 +--exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 > $ndb_backup_file1 +# load the table from the raw data file +eval LOAD DATA INFILE '$ndb_backup_file1' INTO TABLE helper1; +--remove_file $ndb_backup_file1 +# output what we need +eval SELECT * FROM helper1 WHERE c1 LIKE '%520093696%' +INTO OUTFILE '$ndb_backup_file2'; +# cleanup +DROP TABLE helper1; +--enable_warnings +--enable_query_log + +CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info +(id INT, backup_id INT) ENGINE = MEMORY; DELETE FROM test.backup_info; -LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ','; +--replace_result $MYSQLTEST_VARDIR <MYSQLTEST_VARDIR> +eval LOAD DATA INFILE '$ndb_backup_file2' +INTO TABLE test.backup_info FIELDS TERMINATED BY ','; +--remove_file $ndb_backup_file2 --replace_column 1 <the_backup_id> SELECT @the_backup_id:=backup_id FROM test.backup_info; - -let the_backup_id=`select @the_backup_id`; +let $the_backup_id=`SELECT @the_backup_id`; DROP TABLE test.backup_info; diff --git a/mysql-test/include/start_slave.inc b/mysql-test/include/start_slave.inc new file mode 100644 index 00000000000..78a02736de8 --- /dev/null +++ b/mysql-test/include/start_slave.inc @@ -0,0 +1,21 @@ +# ==== Purpose ==== +# +# Issues START SLAVE on the current connection. Then waits until both +# the IO and SQL threads have started, or until a timeout is reached. +# +# Please use this instead of 'START SLAVE', to reduce the risk of test +# case bugs. +# +# ==== Usage ==== +# +# source include/wait_for_slave_to_start.inc; +# +# Parameters to this macro are $slave_timeout and +# $master_connection. See wait_for_slave_param.inc for +# descriptions. + +--disable_query_log +START SLAVE; +--enable_query_log +--echo include/start_slave.inc +source include/wait_for_slave_to_start.inc; diff --git a/mysql-test/include/stop_slave.inc b/mysql-test/include/stop_slave.inc new file mode 100644 index 00000000000..7161e6fe739 --- /dev/null +++ b/mysql-test/include/stop_slave.inc @@ -0,0 +1,21 @@ +# ==== Purpose ==== +# +# Issues STOP SLAVE on the current connection. Then waits until both +# the IO and SQL threads have stopped, or until a timeout is reached. +# +# Please use this instead of 'STOP SLAVE', to reduce the risk of test +# case bugs. +# +# ==== Usage ==== +# +# source include/wait_for_slave_to_start.inc; +# +# Parameters to this macro are $slave_timeout and +# $master_connection. See wait_for_slave_param.inc for +# descriptions. + +--disable_query_log +STOP SLAVE; +--enable_query_log +--echo include/stop_slave.inc +source include/wait_for_slave_to_stop.inc; diff --git a/mysql-test/include/wait_for_slave_sql_error.inc b/mysql-test/include/wait_for_slave_sql_error.inc new file mode 100644 index 00000000000..1a708cee780 --- /dev/null +++ b/mysql-test/include/wait_for_slave_sql_error.inc @@ -0,0 +1,40 @@ +# ==== Purpose ==== +# +# Waits until the SQL thread of the current connection has got an +# error, or until a timeout is reached. Also waits until the SQL +# thread has completely stopped. +# +# ==== Usage ==== +# +# source include/wait_for_slave_sql_error.inc; +# +# Parameters: +# +# $slave_sql_errno +# The expected SQL error number. This is required. +# (After BUG#41956 has been fixed, this will be required to be a +# symbolic name instead of a number.) +# +# $slave_timeout +# See wait_for_slave_param.inc for description. +# +# $master_connection +# See wait_for_slave_param.inc for description. + +if (`SELECT '$slave_sql_errno' = ''`) { + --echo !!!ERROR IN TEST: you must set \$slave_sql_errno before sourcing wait_fro_slave_sql_error.inc + exit; +} + +let $slave_param= Slave_SQL_Running; +let $slave_param_value= No; +let $slave_error_message= Failed while waiting for slave to stop the SQL thread (expecting error in the SQL thread); +source include/wait_for_slave_param.inc; + +# NOTE: on mysql-5.0, there is no way to distinguish slave SQL error from IO error +let $_error= query_get_value(SHOW SLAVE STATUS, Last_Errno, 1); +if (`SELECT '$_error' != '$slave_sql_errno'`) { + --echo Slave stopped with wrong error code: $_error (expected $slave_sql_errno) + source include/show_rpl_debug_info.inc; + exit; +} diff --git a/mysql-test/include/wait_for_slave_sql_error_and_skip.inc b/mysql-test/include/wait_for_slave_sql_error_and_skip.inc new file mode 100644 index 00000000000..5723720f4b7 --- /dev/null +++ b/mysql-test/include/wait_for_slave_sql_error_and_skip.inc @@ -0,0 +1,39 @@ +# ==== Purpose ==== +# +# Wait for slave SQL error, skip the erroneous statement and restart +# slave +# +# ==== Usage ==== +# +# let $slave_sql_error= <ERRNO>; +# source include/wait_for_slave_sql_error_and_skip.inc; +# +# Parameters: +# +# $slave_sql_errno +# The error number to wait for. This is required. (See +# wait_for_slave_sql_error.inc) +# +# $show_sql_error +# If set, will print the error to the query log. +# +# $slave_timeout +# See wait_for_slave_param.inc for description. +# +# $master_connection +# See wait_for_slave_param.inc for description. + +echo --source include/wait_for_slave_sql_error_and_skip.inc; +connection slave; +source include/wait_for_slave_sql_error.inc; +if ($show_sql_error) +{ + # NOTE: on mysql-5.0, there is no way to distinguish slave SQL error from IO error + let $error= query_get_value("SHOW SLAVE STATUS", Last_Error, 1); + echo Last_SQL_Error = $error; +} + +# skip the erroneous statement +set global sql_slave_skip_counter=1; +source include/start_slave.inc; +connection master; diff --git a/mysql-test/include/wait_show_condition.inc b/mysql-test/include/wait_show_condition.inc new file mode 100644 index 00000000000..253101d1e07 --- /dev/null +++ b/mysql-test/include/wait_show_condition.inc @@ -0,0 +1,78 @@ +# include/wait_show_condition.inc +# +# SUMMARY +# +# Waits until the show statement ($show_statement) has at least within one of +# the rows of the result set for the field ($field) a value which fulfils +# a condition ($condition), or the operation times out. +# +# +# USAGE +# +# let $show_statement= SHOW PROCESSLIST; +# let $field= State; +# let $condition= = 'Updating'; +# --source include/wait_show_condition.inc +# +# OR +# +# let $wait_timeout= 60; # Override default of 30 seconds with 60. +# let $show_statement= SHOW PROCESSLIST; +# let $field= State; +# let $condition= = 'Updating'; +# --source include/wait_show_condition.inc +# +# Please do not use this use routine if you can replace the SHOW statement +# with a select. In such a case include/wait_condition.inc is recommended. +# +# Created: 2009-02-18 mleich +# + +let $max_run_time= 30; +if ($wait_timeout) +{ + let $max_run_time= $wait_timeout; +} +# Reset $wait_timeout so that its value won't be used on subsequent +# calls, and default will be used instead. +let $wait_timeout= 0; + +# The smallest timespan till UNIX_TIMESTAMP() gets incremented is ~0 seconds. +# We add one second to avoid the case that somebody measures timespans on a +# real clock with fractions of seconds, detects that n seconds are sufficient, +# assigns n to this routine and suffers because he sometimes gets n - 1 +# seconds in reality. +inc $max_run_time; + +let $found= 0; +let $max_end_time= `SELECT UNIX_TIMESTAMP() + $max_run_time`; +while (`SELECT UNIX_TIMESTAMP() <= $max_end_time AND $found = 0`) +{ + # Sleep a bit to avoid too heavy load. + real_sleep 0.2; + let $rowno= 1; + let $process_result= 1; + while (`SELECT $process_result = 1 AND $found = 0`) + { + let $field_value= query_get_value($show_statement, $field, $rowno); + if (`SELECT '$field_value' $condition`) + { + let $found= 1; + } + if (`SELECT '$field_value' = 'No such row'`) + { + # We are behind the last row of the result set. + let $process_result= 0; + } + inc $rowno; + } +} +if (!$found) +{ + echo # Timeout in include/wait_show_condition.inc for $wait_condition; + echo # show_statement : $show_statement; + echo # field : $field; + echo # condition : $condition; + echo # max_run_time : $max_run_time; +} + diff --git a/mysql-test/include/wait_until_count_sessions.inc b/mysql-test/include/wait_until_count_sessions.inc index 36fa9accafe..56d2b0b1dcd 100644 --- a/mysql-test/include/wait_until_count_sessions.inc +++ b/mysql-test/include/wait_until_count_sessions.inc @@ -2,14 +2,23 @@ # # SUMMARY # -# Waits until the passed number ($count_sessions) of concurrent sessions was -# observed via +# Waits until the passed number ($count_sessions) of concurrent sessions or +# a smaller number was observed via # SHOW STATUS LIKE 'Threads_connected' # or the operation times out. -# Note: Starting with 5.1 we could also use -# SELECT COUNT(*) FROM information_schema.processlist -# I stay with "SHOW STATUS LIKE 'Threads_connected'" because this -# runs in all versions 5.0+ +# Note: +# 1. We wait for $current_sessions <= $count_sessions because in the use case +# with count_sessions.inc before and wait_until_count_sessions.inc after +# the core of the test it could happen that the disconnects of sessions +# belonging to the preceeding test are not finished. +# sessions at test begin($count_sessions) = m + n +# sessions of the previous test which will be soon disconnected = n (n >= 0) +# sessions at test end ($current sessions, assuming the test disconnects +# all additional sessions) = m +# 2. Starting with 5.1 we could also use +# SELECT COUNT(*) FROM information_schema.processlist +# I stay with "SHOW STATUS LIKE 'Threads_connected'" because this +# runs in all versions 5.0+ # # # USAGE @@ -19,7 +28,7 @@ # # OR typical example of a test which uses more than one session # Such a test could harm successing tests if there is no server shutdown -# and start between.cw +# and start between. # # If the testing box is slow than the disconnect of sessions belonging to # the current test might happen when the successing test gets executed. @@ -79,10 +88,14 @@ # backup.test, grant3.test # # -# Created: 2009-01-14 mleich +# Created: +# 2009-01-14 mleich +# Modified: +# 2009-02-24 mleich Fix Bug#43114 wait_until_count_sessions too restrictive, +# random PB failures # -let $wait_counter= 50; +let $wait_counter= 100; if ($wait_timeout) { let $wait_counter= `SELECT $wait_timeout * 10`; @@ -93,7 +106,7 @@ let $wait_timeout= 0; while ($wait_counter) { let $current_sessions= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1); - let $success= `SELECT $current_sessions = $count_sessions`; + let $success= `SELECT $current_sessions <= $count_sessions`; if ($success) { let $wait_counter= 0; @@ -107,6 +120,7 @@ while ($wait_counter) if (!$success) { --echo # Timeout in wait_until_count_sessions.inc - --echo # Number of sessions expected: $count_sessions found: $current_sessions + --echo # Number of sessions expected: <= $count_sessions found: $current_sessions + SHOW PROCESSLIST; } |