1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# ==== 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.
#
# <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 smaller than 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/rpl_assert.inc
#
# Parameters:
#
# $assert_text
# Text that describes what is being checked. By default, this text
# is written to the query log.
#
# $assert_cond
# Condition to check. See above for details about the format. The
# condition will be executed as `SELECT $assert_cond`. Note: this
# condition is parsed using SQL statements, quoted inside single
# quotes, so it must not contain single quotes itself (use double
# quotes for strings).
#
# $assert_quiet
# Do not print $assert_text to the query log.
#
# $rpl_debug
# Print extra debug info.
if ($rpl_debug)
{
--echo # debug: assert_text='$assert_text' assert_cond='$assert_cond'
}
# Sanity-check input
if (`SELECT "$assert_text" = ""`)
{
--die ERROR IN TEST: the mysqltest variable rpl_test must be set
}
# Evaluate square brackets in cond.
--let $_rpl_assert_substmt_number= 1
--let $_rpl_interpolated_cond= $assert_cond
--let $_rpl_assert_lbracket= `SELECT LOCATE('[', '$_rpl_interpolated_cond')`
while ($_rpl_assert_lbracket)
{
# Get position of right bracket
--let $_rpl_assert_rbracket= `SELECT LOCATE(']', '$_rpl_interpolated_cond')`
if (!$_rpl_assert_rbracket)
{
--echo BUG IN TEST: Mismatching square brackets in assert_cond: '$assert_cond'
--die BUG IN TEST: Mismatching square brackets in $assert_cond
}
# Get sub-statement and result of it
--let $_rpl_assert_substmt= `SELECT SUBSTRING('$_rpl_interpolated_cond', $_rpl_assert_lbracket + 1, $_rpl_assert_rbracket - $_rpl_assert_lbracket - 1)`
--let $_rpl_assert_substmt_result= query_get_value($_rpl_assert_substmt)
if ($rpl_debug)
{
--echo # debug: sub-statement='$_rpl_assert_substmt' result='$rpl_assert_result'
}
# Replace sub-statement by its result
--let $_rpl_interpolated_cond= `SELECT REPLACE('$_rpl_interpolated_cond', '[$_rpl_assert_substmt]', '$_rpl_assert_substmt_result')`
# Replace result references by result
--let $_rpl_interpolated_cond= `SELECT REPLACE('$_rpl_interpolated_cond', '<$_rpl_assert_substmt_number>', '$_rpl_assert_substmt_result')`
--let $_rpl_assert_lbracket= `SELECT LOCATE('[', '$_rpl_interpolated_cond')`
--inc $_rpl_assert_substmt_number
}
if ($rpl_debug)
{
--echo # debug: interpolated_cond='$_rpl_interpolated_cond'
}
# Execute.
--let $_rpl_assert_result= `SELECT $_rpl_interpolated_cond`
if ($rpl_debug)
{
--echo # debug: result='$_rpl_assert_result'
}
# Check.
if (!$_rpl_assert_result)
{
--echo ######## Test assertion failed: $assert_text ########
--echo Dumping debug info:
--source include/show_rpl_debug_info.inc
--echo Assertion text: '$assert_text'
--echo Assertion condition: '$assert_cond'
--echo Assertion condition, interpolated: '$_rpl_interpolated_cond'
--echo Assertion result: '$_rpl_assert_result'
--die Test assertion failed in rpl_assertion.inc
}
if (!$assert_quiet)
{
--echo # Asserted this: $assert_text
}
--let $assert_text=
--let $assert_cond=
|