@@ -135,6 +135,77 @@ start_replication() {
135135 done
136136}
137137
138+ build_ghost_command () {
139+ # Build gh-ost command with all standard options
140+ # Expects: ghost_binary, replica_host, replica_port, master_host, master_port,
141+ # table_name, storage_engine, throttle_flag_file, extra_args
142+ cmd=" GOTRACEBACK=crash $ghost_binary \
143+ --user=gh-ost \
144+ --password=gh-ost \
145+ --host=$replica_host \
146+ --port=$replica_port \
147+ --assume-master-host=${master_host} :${master_port} \
148+ --database=test \
149+ --table=${table_name} \
150+ --storage-engine=${storage_engine} \
151+ --alter='engine=${storage_engine} ' \
152+ --exact-rowcount \
153+ --assume-rbr \
154+ --skip-metadata-lock-check \
155+ --initially-drop-old-table \
156+ --initially-drop-ghost-table \
157+ --throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _${table_name} _ghc' \
158+ --throttle-flag-file=$throttle_flag_file \
159+ --serve-socket-file=/tmp/gh-ost.test.sock \
160+ --initially-drop-socket-file \
161+ --test-on-replica \
162+ --default-retries=3 \
163+ --chunk-size=10 \
164+ --verbose \
165+ --debug \
166+ --stack \
167+ --checkpoint \
168+ --execute ${extra_args[@]} "
169+ }
170+
171+ validate_expected_failure () {
172+ # Check if test expected to fail and validate error message
173+ # Expects: tests_path, test_name, execution_result, test_logfile
174+ if [ -f $tests_path /$test_name /expect_failure ]; then
175+ if [ $execution_result -eq 0 ]; then
176+ echo
177+ echo " ERROR $test_name execution was expected to exit on error but did not."
178+ echo " === Last 50 lines of $test_logfile ==="
179+ tail -n 50 $test_logfile
180+ echo " === End log excerpt ==="
181+ return 1
182+ fi
183+ if [ -s $tests_path /$test_name /expect_failure ]; then
184+ # 'expect_failure' file has content. We expect to find this content in the log.
185+ expected_error_message=" $( cat $tests_path /$test_name /expect_failure) "
186+ if grep -q " $expected_error_message " $test_logfile ; then
187+ return 0
188+ fi
189+ echo
190+ echo " ERROR $test_name execution was expected to exit with error message '${expected_error_message} ' but did not."
191+ echo " === Last 50 lines of $test_logfile ==="
192+ tail -n 50 $test_logfile
193+ echo " === End log excerpt ==="
194+ return 1
195+ fi
196+ # 'expect_failure' file has no content. We generally agree that the failure is correct
197+ return 0
198+ fi
199+
200+ if [ $execution_result -ne 0 ]; then
201+ echo
202+ echo " ERROR $test_name execution failure. cat $test_logfile :"
203+ cat $test_logfile
204+ return 1
205+ fi
206+ return 0
207+ }
208+
138209sysbench_prepare () {
139210 local mysql_host=" $1 "
140211 local mysql_port=" $2 "
@@ -253,6 +324,15 @@ test_single() {
253324
254325 table_name=" gh_ost_test"
255326 ghost_table_name=" _gh_ost_test_gho"
327+
328+ # Check for custom test script
329+ if [ -f $tests_path /$test_name /test.sh ]; then
330+ # Source the custom test script which can override default behavior
331+ # It has access to all variables and functions from this script
332+ source $tests_path /$test_name /test.sh
333+ return $?
334+ fi
335+
256336 # test with sysbench oltp write load
257337 if [[ " $test_name " == " sysbench" ]]; then
258338 if ! command -v sysbench & > /dev/null; then
@@ -273,34 +353,8 @@ test_single() {
273353 fi
274354 trap cleanup SIGINT
275355
276- #
277- cmd=" GOTRACEBACK=crash $ghost_binary \
278- --user=gh-ost \
279- --password=gh-ost \
280- --host=$replica_host \
281- --port=$replica_port \
282- --assume-master-host=${master_host} :${master_port}
283- --database=test \
284- --table=${table_name} \
285- --storage-engine=${storage_engine} \
286- --alter='engine=${storage_engine} ' \
287- --exact-rowcount \
288- --assume-rbr \
289- --skip-metadata-lock-check \
290- --initially-drop-old-table \
291- --initially-drop-ghost-table \
292- --throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _${table_name} _ghc' \
293- --throttle-flag-file=$throttle_flag_file \
294- --serve-socket-file=/tmp/gh-ost.test.sock \
295- --initially-drop-socket-file \
296- --test-on-replica \
297- --default-retries=3 \
298- --chunk-size=10 \
299- --verbose \
300- --debug \
301- --stack \
302- --checkpoint \
303- --execute ${extra_args[@]} "
356+ # Build and execute gh-ost command
357+ build_ghost_command
304358 echo_dot
305359 echo $cmd > $exec_command_file
306360 echo_dot
@@ -323,38 +377,9 @@ test_single() {
323377 gh-ost-test-mysql-master --default-character-set=utf8mb4 test < $tests_path /$test_name /destroy.sql
324378 fi
325379
326- if [ -f $tests_path /$test_name /expect_failure ]; then
327- if [ $execution_result -eq 0 ]; then
328- echo
329- echo " ERROR $test_name execution was expected to exit on error but did not."
330- echo " === Last 50 lines of $test_logfile ==="
331- tail -n 50 $test_logfile
332- echo " === End log excerpt ==="
333- return 1
334- fi
335- if [ -s $tests_path /$test_name /expect_failure ]; then
336- # 'expect_failure' file has content. We expect to find this content in the log.
337- expected_error_message=" $( cat $tests_path /$test_name /expect_failure) "
338- if grep -q " $expected_error_message " $test_logfile ; then
339- return 0
340- fi
341- echo
342- echo " ERROR $test_name execution was expected to exit with error message '${expected_error_message} ' but did not."
343- echo " === Last 50 lines of $test_logfile ==="
344- tail -n 50 $test_logfile
345- echo " === End log excerpt ==="
346- return 1
347- fi
348- # 'expect_failure' file has no content. We generally agree that the failure is correct
349- return 0
350- fi
351-
352- if [ $execution_result -ne 0 ]; then
353- echo
354- echo " ERROR $test_name execution failure. cat $test_logfile :"
355- cat $test_logfile
356- return 1
357- fi
380+ # Validate expected failure or success
381+ validate_expected_failure
382+ return $?
358383
359384 gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e " show create table ${ghost_table_name} \G" -ss > $ghost_structure_output_file
360385
0 commit comments