mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
cf9038e979
fails randomly. The problem was that the test case used command line tool (mysql) without specifying connect_timeout argument. In some cases, this lead to hanging of the test case. The fix is to specify --connect_timeout=1 when starting mysql. Also, the patch contains polishing and various cleanups to simplify analyzing of the problems further. The patch affects only test suite, no server codebase has been touched. mysql-test/lib/mtr_im.pl: Remember PID of the IM-spawner -- a process, that is used to fork IM-angel. mysql-test/lib/mtr_io.pl: Trim \n from the PID. mysql-test/lib/mtr_process.pl: Don't complain if it was IM-spawner, who died. mysql-test/r/im_daemon_life_cycle.result: Update the result file. mysql-test/r/im_life_cycle.result: Update the result file. mysql-test/t/im_daemon_life_cycle.imtest: Polishing: add more comments, be more verbose. mysql-test/t/im_life_cycle.imtest: Polishing: be more verbose. mysql-test/t/im_utils.imtest: Polishing: be more verbose. mysql-test/t/kill_n_check.sh: Log messages to the extrenal file so that they can be analyzed if test case failed. mysql-test/t/wait_for_process.sh: Log messages to the extrenal file so that they can be analyzed if test case failed. mysql-test/t/wait_for_socket.sh: Log messages to the extrenal file so that they can be analyzed if test case failed. mysql-test/t/log.sh: Dummy script to facilitate logging from test-scripts. mysql-test/t/utils.sh: A bunch of auxilary functions to facilitate logging.
147 lines
3.4 KiB
Bash
Executable file
147 lines
3.4 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
###########################################################################
|
|
|
|
# NOTE: this script returns 0 (success) even in case of failure (except for
|
|
# usage-error). This is because this script is executed under
|
|
# mysql-test-run[.pl] and it's better to examine particular problem in log
|
|
# file, than just having said that the test case has failed.
|
|
|
|
###########################################################################
|
|
|
|
basename=`basename "$0"`
|
|
dirname=`dirname "$0"`
|
|
|
|
###########################################################################
|
|
|
|
. "$dirname/utils.sh"
|
|
|
|
###########################################################################
|
|
|
|
check_restart()
|
|
{
|
|
if [ ! -r "$pid_path" ]; then
|
|
log_debug "No '$pid_path' found."
|
|
user_msg='the process was killed'
|
|
return 1
|
|
fi
|
|
|
|
new_pid=`cat "$pid_path" 2>/dev/null`
|
|
err_code=$?
|
|
|
|
log_debug "err_code: $err_code; original_pid: $original_pid; new_pid: $new_pid."
|
|
|
|
if [ $err_code -eq 0 -a "$original_pid" = "$new_pid" ]; then
|
|
log_debug "The process was not restarted."
|
|
user_msg='the process was not restarted'
|
|
return 1
|
|
fi
|
|
|
|
log_debug "The process was restarted."
|
|
user_msg='the process was restarted'
|
|
return 0
|
|
}
|
|
|
|
###########################################################################
|
|
|
|
if [ $# -ne 4 ]; then
|
|
echo "Usage: $basename <pid file path> killed|restarted <timeout> <test id>"
|
|
exit 1
|
|
fi
|
|
|
|
pid_path="$1"
|
|
expected_result="$2"
|
|
total_timeout="$3"
|
|
test_id="$4"
|
|
log_file="$MYSQLTEST_VARDIR/log/$test_id.log"
|
|
|
|
log_debug "-- $basename: starting --"
|
|
log_debug "pid_path: '$pid_path'"
|
|
log_debug "expected_result: '$expected_result'"
|
|
log_debug "total_timeout: '$total_timeout'"
|
|
log_debug "test_id: '$test_id'"
|
|
log_debug "log_file: '$log_file'"
|
|
|
|
###########################################################################
|
|
|
|
if [ "$expected_result" != 'killed' -a \
|
|
"$expected_result" != 'restarted' ]; then
|
|
log_error "Invalid second argument ($expected_result): 'killed' or 'restarted' expected."
|
|
quit 0
|
|
fi
|
|
|
|
if [ -z "$pid_path" ]; then
|
|
log_error "Invalid PID path ($pid_path)."
|
|
quit 0
|
|
fi
|
|
|
|
if [ ! -r "$pid_path" ]; then
|
|
log_error "PID file ($pid_path) does not exist."
|
|
quit 0
|
|
fi
|
|
|
|
if [ -z "$total_timeout" ]; then
|
|
log_error "Timeout is not specified."
|
|
quit 0
|
|
fi
|
|
|
|
###########################################################################
|
|
|
|
original_pid=`cat "$pid_path"`
|
|
log_debug "original_pid: $original_pid."
|
|
|
|
log_info "Killing the process..."
|
|
|
|
kill -9 $original_pid
|
|
|
|
###########################################################################
|
|
|
|
log_info "Waiting..."
|
|
|
|
if [ "$expected_result" = "restarted" ]; then
|
|
|
|
# Wait for the process to restart.
|
|
|
|
cur_attempt=1
|
|
|
|
while true; do
|
|
|
|
log_debug "cur_attempt: $cur_attempt."
|
|
|
|
if check_restart; then
|
|
log_info "Success: $user_msg."
|
|
quit 0
|
|
fi
|
|
|
|
[ $cur_attempt -ge $total_timeout ] && break
|
|
|
|
log_debug "Sleeping for 1 second..."
|
|
sleep 1
|
|
|
|
cur_attempt=`expr $cur_attempt + 1`
|
|
|
|
done
|
|
|
|
log_error "$user_msg."
|
|
quit 0
|
|
|
|
else # $expected_result == killed
|
|
|
|
# Here we have to sleep for some long time to ensure that the process will
|
|
# not be restarted.
|
|
|
|
log_debug "Sleeping for $total_timeout seconds..."
|
|
sleep $total_timeout
|
|
|
|
new_pid=`cat "$pid_path" 2>/dev/null`
|
|
log_debug "new_pid: $new_pid."
|
|
|
|
if [ "$new_pid" -a "$new_pid" -ne "$original_pid" ]; then
|
|
log_error "The process was restarted."
|
|
else
|
|
log_info "Success: the process was killed."
|
|
fi
|
|
|
|
quit 0
|
|
|
|
fi
|