Fix for BUG#20716: SHOW INSTANCES statement causes races in IM tests.

  
Fix for the bug in mysql-test-run.pl which prevents other tests succeed
after IM-test failure.
  
The idea of the fix of BUG#20716 is to:
  1. Check each SHOW INSTANCES statement, add necessary "sleep" instruction before;
  2. Move all environment checkings into the one file and include it everywhere.
parent ed2d8cce
# This file is intended to be used in each IM-test. It contains stamements,
# that ensure that starting conditions (environment) for the IM-test are as
# expected.
# Wait for mysqld1 (guarded instance) to start.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
# Check the running instances.
--connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK)
--connection mysql1_con
SHOW VARIABLES LIKE 'server_id';
--connection default
# Let IM detect that mysqld1 is online. This delay should be longer than
# monitoring interval.
--sleep 2
# Check that IM understands that mysqld1 is online, while mysqld2 is
# offline.
SHOW INSTANCES;
...@@ -2898,12 +2898,16 @@ sub im_stop($) { ...@@ -2898,12 +2898,16 @@ sub im_stop($) {
while (1) while (1)
{ {
# Check that IM-main died.
if (kill (0, $instance_manager->{'pid'})) if (kill (0, $instance_manager->{'pid'}))
{ {
mtr_debug("IM-main is still alive."); mtr_debug("IM-main is still alive.");
last; last;
} }
# Check that IM-angel died.
if (defined $instance_manager->{'angel_pid'} && if (defined $instance_manager->{'angel_pid'} &&
kill (0, $instance_manager->{'angel_pid'})) kill (0, $instance_manager->{'angel_pid'}))
{ {
...@@ -2911,21 +2915,39 @@ sub im_stop($) { ...@@ -2911,21 +2915,39 @@ sub im_stop($) {
last; last;
} }
# Check that all guarded mysqld-instances died.
my $guarded_mysqlds_dead= 1;
foreach my $pid (@mysqld_pids) foreach my $pid (@mysqld_pids)
{ {
if (kill (0, $pid)) if (kill (0, $pid))
{ {
mtr_debug("Guarded mysqld ($pid) is still alive."); mtr_debug("Guarded mysqld ($pid) is still alive.");
$guarded_mysqlds_dead= 0;
last; last;
} }
} }
last unless $guarded_mysqlds_dead;
# Ok, all necessary processes are dead.
$clean_shutdown= 1; $clean_shutdown= 1;
last; last;
} }
# Kill leftovers (the order is important). # Kill leftovers (the order is important).
if ($clean_shutdown)
{
mtr_debug("IM-shutdown was clean -- all processed died.");
}
else
{
mtr_debug("IM failed to shutdown gracefully. We have to clean the mess...");
}
unless ($clean_shutdown) unless ($clean_shutdown)
{ {
......
Success: the process has been started. Success: the process has been started.
SHOW VARIABLES LIKE 'server_id';
Variable_name Value
server_id 1
SHOW INSTANCES; SHOW INSTANCES;
instance_name status instance_name status
mysqld1 online mysqld1 online
......
--------------------------------------------------------------------
-- 1.1.1.
--------------------------------------------------------------------
Success: the process has been started. Success: the process has been started.
SHOW VARIABLES LIKE 'server_id';
Variable_name Value
server_id 1
SHOW INSTANCES; SHOW INSTANCES;
instance_name status instance_name status
mysqld1 online mysqld1 online
...@@ -40,10 +39,6 @@ ERROR HY000: Bad instance name. Check that the instance with such a name exists ...@@ -40,10 +39,6 @@ ERROR HY000: Bad instance name. Check that the instance with such a name exists
-------------------------------------------------------------------- --------------------------------------------------------------------
-- 1.1.6. -- 1.1.6.
-------------------------------------------------------------------- --------------------------------------------------------------------
SHOW INSTANCES;
instance_name status
mysqld1 online
mysqld2 offline
Killing the process... Killing the process...
Sleeping... Sleeping...
Success: the process was restarted. Success: the process was restarted.
......
server_id = 1 Success: the process has been started.
server_id = 2
SHOW VARIABLES LIKE 'server_id'; SHOW VARIABLES LIKE 'server_id';
Variable_name Value Variable_name Value
server_id 1 server_id 1
SHOW INSTANCES;
instance_name status
mysqld1 online
mysqld2 offline
SET mysqld1.server_id = 11; SET mysqld1.server_id = 11;
server_id =11 server_id =11
server_id = 2 server_id = 2
......
server_id = 1 Success: the process has been started.
server_id = 2
SHOW VARIABLES LIKE 'server_id'; SHOW VARIABLES LIKE 'server_id';
Variable_name Value Variable_name Value
server_id 1 server_id 1
SHOW INSTANCES;
instance_name status
mysqld1 online
mysqld2 offline
UNSET mysqld1.server_id; UNSET mysqld1.server_id;
server_id = 2 server_id = 2
SHOW VARIABLES LIKE 'server_id'; SHOW VARIABLES LIKE 'server_id';
......
Success: the process has been started. Success: the process has been started.
SHOW VARIABLES LIKE 'server_id';
Variable_name Value
server_id 1
SHOW INSTANCES; SHOW INSTANCES;
instance_name status instance_name status
mysqld1 online mysqld1 online
......
...@@ -7,21 +7,7 @@ ...@@ -7,21 +7,7 @@
########################################################################### ###########################################################################
--source include/im_check_os.inc --source include/im_check_os.inc
--source include/im_check_env.inc
###########################################################################
# Wait for mysqld1 (guarded instance) to start.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
# Let IM detect that mysqld1 is online. This delay should be longer than
# monitoring interval.
--sleep 3
# Check that start conditions are as expected.
SHOW INSTANCES;
########################################################################### ###########################################################################
......
...@@ -7,33 +7,7 @@ ...@@ -7,33 +7,7 @@
########################################################################### ###########################################################################
--source include/im_check_os.inc --source include/im_check_os.inc
--source include/im_check_env.inc
###########################################################################
#
# 1.1.1. Check that Instance Manager is able:
# - to read definitions of two mysqld-instances;
# - to start the first instance;
# - to understand 'nonguarded' option and keep the second instance down;
#
###########################################################################
--echo
--echo --------------------------------------------------------------------
--echo -- 1.1.1.
--echo --------------------------------------------------------------------
# Wait for mysqld1 (guarded instance) to start.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
# Let IM detect that mysqld1 is online. This delay should be longer than
# monitoring interval.
--sleep 3
# Check that start conditions are as expected.
SHOW INSTANCES;
########################################################################### ###########################################################################
# #
...@@ -54,9 +28,10 @@ START INSTANCE mysqld2; ...@@ -54,9 +28,10 @@ START INSTANCE mysqld2;
# FIXME: START INSTANCE should be synchronous. # FIXME: START INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started
# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is # FIXME: Result of SHOW INSTANCES here is not deterministic unless START
# synchronous. Even waiting for mysqld to start by looking at its pid file is # INSTANCE is synchronous. Even waiting for mysqld to start by looking at
# not enough, because IM may not detect that mysqld has started. # its pid file is not enough, because it is unknown when IM detects that
# mysqld has started.
# SHOW INSTANCES; # SHOW INSTANCES;
--connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD2_PORT,$IM_MYSQLD2_SOCK) --connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD2_PORT,$IM_MYSQLD2_SOCK)
...@@ -86,9 +61,10 @@ STOP INSTANCE mysqld2; ...@@ -86,9 +61,10 @@ STOP INSTANCE mysqld2;
# FIXME: STOP INSTANCE should be synchronous. # FIXME: STOP INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped
# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is # FIXME: Result of SHOW INSTANCES here is not deterministic unless START
# synchronous. Even waiting for mysqld to start by looking at its pid file is # INSTANCE is synchronous. Even waiting for mysqld to start by looking at
# not enough, because IM may not detect that mysqld has started. # its pid file is not enough, because it is unknown when IM detects that
# mysqld has started.
# SHOW INSTANCES; # SHOW INSTANCES;
########################################################################### ###########################################################################
...@@ -114,8 +90,8 @@ START INSTANCE mysqld1; ...@@ -114,8 +90,8 @@ START INSTANCE mysqld1;
########################################################################### ###########################################################################
# #
# 1.1.5. Check that Instance Manager reports correct errors for 'STOP INSTANCE' # 1.1.5. Check that Instance Manager reports correct errors for
# command: # 'STOP INSTANCE' command:
# - if the client tries to start unregistered instance; # - if the client tries to start unregistered instance;
# - if the client tries to start already stopped instance; # - if the client tries to start already stopped instance;
# - if the client submits invalid arguments; # - if the client submits invalid arguments;
...@@ -146,12 +122,10 @@ STOP INSTANCE mysqld3; ...@@ -146,12 +122,10 @@ STOP INSTANCE mysqld3;
--echo -- 1.1.6. --echo -- 1.1.6.
--echo -------------------------------------------------------------------- --echo --------------------------------------------------------------------
SHOW INSTANCES;
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted 30 --exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted 30
# Give some time to IM to detect that mysqld was restarted. It should be longer # Give some time to IM to detect that mysqld was restarted. It should be
# than monitoring interval. # longer than monitoring interval.
--sleep 3 --sleep 3
...@@ -172,16 +146,18 @@ START INSTANCE mysqld2; ...@@ -172,16 +146,18 @@ START INSTANCE mysqld2;
# FIXME: START INSTANCE should be synchronous. # FIXME: START INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started
# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is # FIXME: Result of SHOW INSTANCES here is not deterministic unless START
# synchronous. Even waiting for mysqld to start by looking at its pid file is # INSTANCE is synchronous. Even waiting for mysqld to start by looking at
# not enough, because IM may not detect that mysqld has started. # its pid file is not enough, because it is unknown when IM detects that
# mysqld has started.
# SHOW INSTANCES; # SHOW INSTANCES;
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed 10 --exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed 10
# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is # FIXME: Result of SHOW INSTANCES here is not deterministic unless START
# synchronous. Even waiting for mysqld to start by looking at its pid file is # INSTANCE is synchronous. Even waiting for mysqld to start by looking at
# not enough, because IM may not detect that mysqld has started. # its pid file is not enough, because it is unknown when IM detects that
# mysqld has started.
# SHOW INSTANCES; # SHOW INSTANCES;
########################################################################### ###########################################################################
......
...@@ -39,32 +39,7 @@ ...@@ -39,32 +39,7 @@
########################################################################### ###########################################################################
--source include/im_check_os.inc --source include/im_check_os.inc
--source include/im_check_env.inc
###########################################################################
#
# 0. Check starting conditions.
#
###########################################################################
# - check the configuration file;
--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ;
# - check the running instances.
--connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK)
--connection mysql1_con
SHOW VARIABLES LIKE 'server_id';
--connection default
# - check the internal cache.
# TODO: we should check only server_id option here.
# SHOW INSTANCE OPTIONS mysqld1;
# SHOW INSTANCE OPTIONS mysqld2;
########################################################################### ###########################################################################
# #
......
...@@ -46,32 +46,7 @@ ...@@ -46,32 +46,7 @@
########################################################################### ###########################################################################
--source include/im_check_os.inc --source include/im_check_os.inc
--source include/im_check_env.inc
###########################################################################
#
# 0. Check starting conditions.
#
###########################################################################
# - check the configuration file;
--exec grep server_id $MYSQLTEST_VARDIR/im.cnf ;
# - check the running instances.
--connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK)
--connection mysql1_con
SHOW VARIABLES LIKE 'server_id';
--connection default
# - check the internal cache.
# TODO: we should check only server_id option here.
# SHOW INSTANCE OPTIONS mysqld1;
# SHOW INSTANCE OPTIONS mysqld2;
########################################################################### ###########################################################################
# #
......
...@@ -7,33 +7,14 @@ ...@@ -7,33 +7,14 @@
########################################################################### ###########################################################################
--source include/im_check_os.inc --source include/im_check_os.inc
--source include/im_check_env.inc
########################################################################### ###########################################################################
# #
# Check starting conditions. This test case assumes that: # Check 'SHOW INSTANCE OPTIONS' command.
# - two mysqld-instances are registered;
# - the first instance is online;
# - the second instance is offline;
# #
# Since configuration of an mysqld-instance contains directories, we should
# Wait for mysqld1 (guarded instance) to start.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
# Let IM detect that mysqld1 is online. This delay should be longer than
# monitoring interval.
--sleep 3
# Check that start conditions are as expected.
SHOW INSTANCES;
#
# Check 'SHOW INSTANCE OPTIONS' command:
# - check that options of both offline and online instances are accessible;
# - since configuration of an mysqld-instance contains directories, we should
# completely ignore the second column (values) in order to make the test # completely ignore the second column (values) in order to make the test
# case produce the same results on different installations; # case produce the same results on different installations;
# TODO: ignore values of only directory-specific options. # TODO: ignore values of only directory-specific options.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment