mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
09c80e12c5
Major replication test framework cleanup. This does the following: - Ensure that all tests clean up the replication state when they finish, by making check-testcase check the output of SHOW SLAVE STATUS. This implies: - Slave must not be running after test finished. This is good because it removes the risk for sporadic errors in subsequent tests when a test forgets to sync correctly. - Slave SQL and IO errors must be cleared when test ends. This is good because we will notice if a test gets an unexpected error in the slave threads near the end. - We no longer have to clean up before a test starts. - Ensure that all tests that wait for an error in one of the slave threads waits for a specific error. It is no longer possible to source wait_for_slave_[sql|io]_to_stop.inc when there is an error in one of the slave threads. This is good because: - If a test expects an error but there is a bug that causes another error to happen, or if it stops the slave thread without an error, then we will notice. - When developing tests, wait_for_*_to_[start|stop].inc will fail immediately if there is an error in the relevant slave thread. Before this patch, we had to wait for the timeout. - Remove duplicated and repeated code for setting up unusual replication topologies. Now, there is a single file that is capable of setting up arbitrary topologies (include/rpl_init.inc, but include/master-slave.inc is still available for the most common topology). Tests can now end with include/rpl_end.inc, which will clean up correctly no matter what topology is used. The topology can be changed with include/rpl_change_topology.inc. - Improved debug information when tests fail. This includes: - debug info is printed on all servers configured by include/rpl_init.inc - User can set $rpl_debug=1, which makes auxiliary replication files print relevant debug info. - Improved documentation for all auxiliary replication files. Now they describe purpose, usage, parameters, and side effects. - Many small code cleanups: - Made have_innodb.inc output a sensible error message. - Moved contents of rpl000017-slave.sh into rpl000017.test - Added mysqltest variables that expose the current state of disable_warnings/enable_warnings and friends. - Too many to list here: see per-file comments for details.
175 lines
5.6 KiB
PHP
175 lines
5.6 KiB
PHP
# ==== Purpose ====
|
|
#
|
|
# Check if a condition holds, fail with debug info if not.
|
|
#
|
|
# The condition is parsed before executed. The following constructs
|
|
# are supported:
|
|
#
|
|
# [SQL_STATEMENT, COLUMN, ROW]
|
|
# The square bracket is replaced by the result from SQL_STATEMENT,
|
|
# in the given COLUMN and ROW.
|
|
#
|
|
# Optionally, SQL_STATEMENT may have the form:
|
|
# connection:SQL_STATEMENT
|
|
# In this case, SQL_STATEMENT is executed on the named connection.
|
|
# All other queries executed by this script will be executed on
|
|
# the connection that was in use when this script was started.
|
|
# The current connection will also be restored at the end of this
|
|
# script.
|
|
#
|
|
# Nested sub-statements on this form are not allowed.
|
|
#
|
|
# <1>
|
|
# This is a shorthand for the result of the first executed square
|
|
# bracket. <2> is a shorthand for the second executed square
|
|
# bracket, and so on.
|
|
#
|
|
# ==== Usage ====
|
|
#
|
|
# --let $assert_text= Relay_Log_Pos must be between min_pos and max_pos
|
|
# --let $assert_cond= [SHOW SLAVE STATUS, Relay_Log_Pos, 1] >= $min_pos AND <1> <= $max_pos
|
|
# [--let $assert_quiet= 1]
|
|
# [--let $rpl_debug= 1]
|
|
# --source include/assert.inc
|
|
#
|
|
# Parameters:
|
|
#
|
|
# $assert_text
|
|
# Text that describes what is being checked. This text is written to
|
|
# the query log so it should not contain non-deterministic elements.
|
|
#
|
|
# $assert_cond
|
|
# Condition to check. See above for details about the format. The
|
|
# condition will be executed as `SELECT $assert_cond`.
|
|
#
|
|
# Both $assert_cond and the result from any substatement on the
|
|
# form [SQL_STATEMENT, COLUMN, ROW] will be used in SQL statements,
|
|
# inside single quotes (as in '$assert_text'). So any single quotes
|
|
# in these texts must be escaped or replaced by double quotes.
|
|
#
|
|
# $rpl_debug
|
|
# Print extra debug info.
|
|
|
|
|
|
--let $include_filename= assert.inc [$assert_text]
|
|
--source include/begin_include_file.inc
|
|
|
|
if ($rpl_debug)
|
|
{
|
|
--echo # debug: assert_text='$assert_text' assert_cond='$assert_cond'
|
|
}
|
|
|
|
# Sanity-check input
|
|
if (!$assert_text)
|
|
{
|
|
--die ERROR IN TEST: the mysqltest variable rpl_test must be set
|
|
}
|
|
|
|
--let $_assert_old_connection= $CURRENT_CONNECTION
|
|
|
|
# Evaluate square brackets in cond.
|
|
--let $_assert_substmt_number= 1
|
|
--let $_assert_cond_interp= '$assert_cond'
|
|
--let $_assert_lbracket= `SELECT LOCATE('[', $_assert_cond_interp)`
|
|
while ($_assert_lbracket)
|
|
{
|
|
# Get position of right bracket
|
|
--let $_assert_rbracket= `SELECT LOCATE(']', $_assert_cond_interp)`
|
|
if (!$_assert_rbracket)
|
|
{
|
|
--echo BUG IN TEST: Mismatching square brackets in assert_cond.
|
|
--echo Original assert_cond='$assert_cond'
|
|
--echo Interpolated assert_cond=$_assert_cond_interp
|
|
--die BUG IN TEST: Mismatching square brackets in $assert_cond
|
|
}
|
|
|
|
# Get sub-statement from statement. Preserve escapes for single quotes.
|
|
--let $_assert_full_substmt= `SELECT QUOTE(SUBSTRING($_assert_cond_interp, $_assert_lbracket + 1, $_assert_rbracket - $_assert_lbracket - 1))`
|
|
|
|
# Get connection from sub-statement
|
|
--let $_assert_colon= `SELECT IF($_assert_full_substmt REGEXP '^[a-zA-Z_][a-zA-Z_0-9]*:', LOCATE(':', $_assert_full_substmt), 0)`
|
|
--let $_assert_connection=
|
|
--let $_assert_substmt= $_assert_full_substmt
|
|
if ($_assert_colon)
|
|
{
|
|
--let $_assert_connection= `SELECT SUBSTRING($_assert_substmt, 1, $_assert_colon - 1)`
|
|
# Preserve escapes for single quotes.
|
|
--let $_assert_substmt= `SELECT QUOTE(SUBSTRING($_assert_substmt, $_assert_colon + 1))`
|
|
}
|
|
|
|
# Interpolate escapes before using condition outside string context.
|
|
--let $_assert_substmt_interp= `SELECT $_assert_substmt`
|
|
|
|
# Execute and get result from sub-statement
|
|
if ($_assert_connection)
|
|
{
|
|
if ($rpl_debug)
|
|
{
|
|
--echo # debug: connection='$_assert_connection' sub-statement=$_assert_substmt
|
|
}
|
|
--let $rpl_connection_name= $_assert_connection
|
|
--source include/rpl_connection.inc
|
|
--let $_assert_substmt_result= query_get_value($_assert_substmt_interp)
|
|
--let $rpl_connection_name= $_assert_old_connection
|
|
--source include/rpl_connection.inc
|
|
}
|
|
if (!$_assert_connection)
|
|
{
|
|
if ($rpl_debug)
|
|
{
|
|
--echo # debug: old connection, sub-statement=$_assert_substmt
|
|
}
|
|
--let $_assert_substmt_result= query_get_value($_assert_substmt_interp)
|
|
}
|
|
if ($rpl_debug)
|
|
{
|
|
--echo # debug: result of sub-statement='$_assert_substmt_result'
|
|
}
|
|
|
|
# Replace sub-statement by its result
|
|
--let $_assert_cond_interp= `SELECT QUOTE(REPLACE($_assert_cond_interp, CONCAT('[', $_assert_full_substmt, ']'), '$_assert_substmt_result'))`
|
|
# Replace result references by result
|
|
--let $_assert_cond_interp= `SELECT QUOTE(REPLACE($_assert_cond_interp, '<$_assert_substmt_number>', '$_assert_substmt_result'))`
|
|
|
|
--let $_assert_lbracket= `SELECT LOCATE('[', $_assert_cond_interp)`
|
|
|
|
--inc $_assert_substmt_number
|
|
}
|
|
|
|
# Interpolate escapes before using condition outside string context.
|
|
--let $_assert_cond_interp= `SELECT $_assert_cond_interp`
|
|
|
|
if ($rpl_debug)
|
|
{
|
|
--echo # debug: interpolated_cond='$_assert_cond_interp'
|
|
}
|
|
|
|
# Execute.
|
|
--let $_assert_result= `SELECT $_assert_cond_interp`
|
|
|
|
if ($rpl_debug)
|
|
{
|
|
--echo # debug: result='$_assert_result'
|
|
}
|
|
|
|
# Check.
|
|
if (!$_assert_result)
|
|
{
|
|
--echo ######## Test assertion failed: $assert_text ########
|
|
--echo Dumping debug info:
|
|
if ($rpl_inited)
|
|
{
|
|
--source include/show_rpl_debug_info.inc
|
|
}
|
|
--echo Assertion text: '$assert_text'
|
|
--echo Assertion condition: '$assert_cond'
|
|
--echo Assertion condition, interpolated: '$_assert_cond_interp'
|
|
--echo Assertion result: '$_assert_result'
|
|
--die Test assertion failed in assertion.inc
|
|
}
|
|
|
|
--let $include_filename= assert.inc [$assert_text]
|
|
--source include/end_include_file.inc
|
|
|
|
--let $assert_text=
|
|
--let $assert_cond=
|