Debian Codegraph @

mysql-test/suite/x/include/assert_error_log_sequence.inc

raw
1 # ==== Purpose ====
2 #
3 # Assert that the error log contains a given messages. The messages
4 # are given as a sequence of regular expressions. User must notice:
5 # a) that all message types are inspected ERROR, INFO, WARNINGS,
6 # b) the messages in error log must appear in the same sequence as
7 # in given regular expressions,
8 # c) listing error message here doesn't add the error to exception
9 # list.
10 # The script inspects only the tail of the error log generated from
11 # the last invocation of `include/save_error_log_position.inc`,
12 # or from the last invocation of this script; whatever happened most
13 # recently.
14 #
15 # ==== Usage ====
16 #
17 # --source include/save_error_log_position.inc
18 # ... generate some errors...
19 # let $error_pattern = {
20 # ERROR_1_REGEX
21 # ERROR_2_REGEX
22 # ...
23 # | SAVEPOS };
24 # [--let $assert_dont_fail = 1]
25 # [--let $keep_old_error_log_position = 1]
26 # [--let $error_log_server_number = NUMBER]
27 # --source include/assert_error_log.inc
28 #
29 # Parameters:
30 #
31 # $error_pattern
32 #
33 # Normally this is a string containing a regular expression,
34 # matching the expected error.
35 #
36 # This can be a multi-line string: the first line matches the
37 # first error, the second line matches the second error, and so
38 # on.
39 #
40 # The special value SAVEPOS is used by
41 # save_error_log_position.inc It should not normally be used in
42 # any other context.
43 #
44 # $keep_old_error_log_position
45 #
46 # Normally, this script saves the current error log position after
47 # reading the error log, so that the next invocation of
48 # assert_error_log.inc starts after the current position.
49 #
50 # To keep the old position, set this variable to 1.
51 #
52 # $assert_dont_fail
53 #
54 # If set to 1, failure to match the regular expression does not
55 # make the test fail immediately. The output will fail with result
56 # mismatch but the test can complete. This can be used during
57 # test development and debugging, but must not be used in tests
58 # that are pushed to a main branch.
59 #
60 # $error_log_server_number
61 #
62 # By default, this script operates on the error log for the server
63 # of the current connection. To use this script from a connection
64 # on a different server, set this to the number of the server
65 # whose log should be inspected.
66
67 # Get server number
68 --let $_ael_server_number = $error_log_server_number
69 if (!$_ael_server_number) {
70 --let $_ael_server_number = `SELECT @@global.server_id`
71 }
72
73 --let $include_filename = assert_error_log_sequence.inc [server: $_ael_server_number, pattern: $error_pattern]
74 --source include/begin_include_file.inc
75
76 --source include/disable_binlog.inc
77
78 if (!$rpl_debug) {
79 --disable_query_log
80 }
81
82
83 # Get error log filename
84 --let $_ael_error_log_filename_save = $error_log_filename
85 if (!$error_log_filename) {
86 if ($error_log_server_number) {
87 --let $error_log_filename = $MYSQLTEST_VARDIR/log/mysqld.$_ael_server_number.err
88 }
89 if (!$error_log_server_number) {
90 --let $error_log_filename = `SELECT IF(@@global.log_error = 'stderr', CONCAT('$MYSQLTEST_VARDIR/log/mysqld.', $_ael_server_number, '.err'), @@global.log_error)`
91 }
92 }
93
94 # Get line count to skip
95 if (!$_ael_positions) {
96 --let $_ael_positions = {"1":-1,"2":-1,"3":-1,"4":-1,"5":-1,"6":-1,"7":-1,"8":-1,"9":-1,"10":-1}
97 }
98 --let $json_object = $_ael_positions
99 --let $json_key = $_ael_server_number
100 --source include/json_lookup.inc
101 --let $ignore_line_count = $json_value
102 if ($ignore_line_count == -1) {
103 if ($error_pattern != SAVEPOS) {
104 if ($error_pattern != SHOW) {
105 --die !!!ERROR IN TEST: use save_error_log_position.inc before the first call to assert_error_log.inc. The error log may contain errors from earlier test runs.
106 }
107 }
108 --let $ignore_line_count = 0
109 }
110
111 # Load error log from file into temporary table
112 --source include/load_error_log.inc
113
114 if ($rpl_debug) {
115 SELECT * FROM mtr.error_log;
116 }
117
118 # Compute number of errors.
119 --let $_ael_error_count = `SELECT COUNT(*) FROM mtr.error_log`
120 if ($rpl_debug) {
121 --echo # ignored $ignore_line_count lines from the error log
122 --echo # found $_ael_error_count new lines after that position
123 }
124
125 # Update position
126 --expr $_ael_new_offset = $ignore_line_count + $_ael_error_count
127 if (!$keep_old_error_log_position) {
128 --let $_ael_positions = `SELECT JSON_SET('$json_object', '$."$_ael_server_number"', $_ael_new_offset)`
129
130 if ($rpl_debug) {
131 --echo _ael_positions=<$_ael_positions>
132 }
133 }
134
135 if ($error_pattern != SAVEPOS) {
136
137
138 # Load expected error patterns from $error_pattern into temporary table.
139 CREATE TEMPORARY TABLE mtr.error_patterns (id INT PRIMARY KEY AUTO_INCREMENT, pattern TEXT);
140
141 # tmp_error_patterns contains all rows of $error_pattern, including comments and empty lines.
142 CREATE TEMPORARY TABLE mtr.tmp_error_patterns (id INT PRIMARY KEY AUTO_INCREMENT, pattern TEXT);
143 # Convert a multi-line string into a multi-row INSERT, by replacing
144 # newlines by:
145 # '),('
146 # Apply QUOTE before the newline-to-multirow conversion, so that
147 # quotes within each message remain escaped but quotes that surround
148 # each row remain unescaped.
149 --let $_ael_pattern_escaped = escape(\',$error_pattern)
150 --let $_ael_pattern_list = `SELECT REPLACE(QUOTE('$_ael_pattern_escaped'), '\n', "'),('")`
151 eval INSERT INTO mtr.tmp_error_patterns(pattern) VALUES($_ael_pattern_list);
152 # Filter out empty lines and comments
153 INSERT INTO mtr.error_patterns(pattern) SELECT pattern FROM mtr.tmp_error_patterns WHERE pattern NOT REGEXP '^ *(#.*)?$' ORDER BY id;
154 DROP TEMPORARY TABLE mtr.tmp_error_patterns;
155
156 --let $_ael_pattern_count = `SELECT COUNT(*) FROM mtr.error_patterns`
157
158
159 # Check all error-messages
160 UPDATE mtr.error_log SET suspicious = 0;
161 UPDATE mtr.error_log as l
162 SET suspicious=(select count(*)>0 from mtr.error_patterns as p where l.line rlike p.pattern);
163
164 # Move filtered-in rows to a a new table in order to recompute the
165 # autoincrement column so that it becomes consecutive and can be
166 # joined with the pattern table.
167 CREATE TEMPORARY TABLE mtr.filtered_error_log (id INT PRIMARY KEY AUTO_INCREMENT, message TEXT);
168 INSERT INTO mtr.filtered_error_log(message) SELECT line FROM mtr.error_log WHERE suspicious = 1 ORDER BY id;
169 if ($rpl_debug) {
170 SELECT * FROM mtr.filtered_error_log;
171 }
172
173 --let $_ael_included_error_count = `SELECT COUNT(*) FROM mtr.filtered_error_log`
174
175 # Check if the number of errors is as expected
176 if ($_ael_included_error_count != $_ael_pattern_count) {
177 --expr $_ael_excluded_error_count = $_ael_error_count - $_ael_included_error_count
178 --echo Expected $_ael_pattern_count errors in the error log, but got $_ael_included_error_count.
179 --echo We excluded the first $ignore_line_count lines. From the remaining $_ael_error_count lines (up to line $_ael_new_offset), we excluded $_ael_excluded_error_count lines that matched a suppression pattern.
180 --let $_ael_failure = 1
181 }
182
183 # Check if the error texts match the patterns
184 if ($_ael_included_error_count == $_ael_pattern_count) {
185 --let $_ael_find_mismatch = FROM mtr.filtered_error_log e, mtr.error_patterns p WHERE e.id = p.id AND NOT e.message REGEXP p.pattern
186 --let $_ael_mismatch_count = `SELECT COUNT(*) $_ael_find_mismatch`
187 if ($_ael_mismatch_count) {
188 --echo There were $_ael_mismatch_count error log lines which did not match the expected pattern:
189 --let $_ael_offset = 0
190 while ($_ael_offset < $_ael_mismatch_count) {
191 --let $_ael_error = `SELECT e.message $_ael_find_mismatch LIMIT $_ael_offset, 1`
192 --let $_ael_pattern = `SELECT p.pattern $_ael_find_mismatch LIMIT $_ael_offset, 1`
193 --inc $_ael_offset
194 --echo Mismatch $_ael_offset: error: <$_ael_error>
195 --echo Mismatch $_ael_offset: pattern: <$_ael_pattern>
196 }
197 --let $_ael_failure = 1
198 }
199 }
200
201 # Report error
202 if ($_ael_failure) {
203 --echo Error patterns:
204 SELECT * FROM mtr.error_patterns;
205 --echo Errors found in log on server $_ael_server_number:
206 SELECT * FROM mtr.filtered_error_log;
207 if (!$assert_dont_fail) {
208 --die Errors did not match the expected list of patterns.
209 }
210 }
211
212 DROP TEMPORARY TABLE mtr.error_patterns;
213
214 if ($error_pattern == SHOW) {
215 if (!$assert_error_log_printed_do_not_check_in_this_line) {
216 --let $assert_error_log_printed_do_not_check_in_this_line = 1
217 --echo DO_NOT_CHECK_IN_THIS_LINE: include/show_error_log.inc should only be used for debugging. Never check in a test that calls it on success.
218 }
219 --echo # There were $_ael_included_error_count new errors on server $_ael_server_number:
220 if ($_ael_included_error_count) {
221 SELECT * FROM mtr.filtered_error_log;
222 }
223 }
224
225 DROP TEMPORARY TABLE mtr.filtered_error_log;
226 }
227
228 DROP TEMPORARY TABLE mtr.error_log;
229
230 --let $error_log_filename = $_ael_error_log_filename_save
231 --source include/restore_binlog.inc
232
233 --let $include_filename = assert_error_log_sequence.inc
234 --source include/end_include_file.inc