mariadb/mysql-test/main/host_cache_size_functionality.test
Sergei Golubchik bead24b7f3 mariadb-test: wait on disconnect
Remove one of the major sources of race condiitons in mariadb-test.
Normally, mariadb_close() sends COM_QUIT to the server and immediately
disconnects. In mariadb-test it means the test can switch to another
connection and sends queries to the server before the server even
started parsing the COM_QUIT packet and these queries can see the
connection as fully active, as it didn't reach dispatch_command yet.

This is a major source of instability in tests and many - but not all,
still less than a half - tests employ workarounds. The correct one
is a pair count_sessions.inc/wait_until_count_sessions.inc.
Also very popular was wait_until_disconnected.inc, which was completely
useless, because it verifies that the connection is closed, and after
disconnect it always is, it didn't verify whether the server processed
COM_QUIT. Sadly the placebo was as widely used as the real thing.

Let's fix this by making mariadb-test `disconnect` command _to wait_ for
the server to confirm. This makes almost all workarounds redundant.

In some cases count_sessions.inc/wait_until_count_sessions.inc is still
needed, though, as only `disconnect` command is changed:

 * after external tools, like `exec $MYSQL`
 * after failed `connect` command
 * replication, after `STOP SLAVE`
 * Federated/CONNECT/SPIDER/etc after `DROP TABLE`

and also in some XA tests, because an XA transaction is dissociated from
the THD very late, after the server has closed the client connection.

Collateral cleanups: fix comments, remove some redundant statements:
 * DROP IF EXISTS if nothing is known to exist
 * DROP table/view before DROP DATABASE
 * REVOKE privileges before DROP USER
 etc
2025-07-16 09:14:33 +07:00

125 lines
5.6 KiB
Text

###############################################################################
# #
# Variable Name: Host_Cache_Size #
# Scope: Global #
# Access Type: Dynamic #
# Data Type: numeric #
# #
# #
# Creation Date: 2012-08-31 #
# Author : Tanjot Singh Uppal #
# #
# #
# Description:Test Cases of Dynamic System Variable Host_Cache_Size #
# that checks the behavior of this variable in the following ways #
# * Value Check #
# * Scope Check #
# * Functionality Check #
# * Accessibility Check #
# #
# This test does not perform the crash recovery on this variable #
# For crash recovery test on default change please run the ibtest #
###############################################################################
-- source include/have_innodb.inc
-- source include/not_embedded.inc
-- source include/have_innodb_16k.inc
--disable_warnings
echo '#________________________VAR_06_Host_Cache_Size__________________#'
echo '##'
--echo '#---------------------WL6372_VAR_6_01----------------------#'
####################################################################
# Checking default value #
####################################################################
select @@global.Host_Cache_Size > 0;
--echo 1 Expected
--echo '#---------------------WL6372_VAR_6_02----------------------#'
#################################################################################
# Checking the Default value post starting the server with other value #
#################################################################################
--echo # Restart server with Host_Cache_Size 1
let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
--write_line wait $restart_file
--shutdown_server
--source include/wait_until_disconnected.inc
--write_line "restart:--host_cache_size=1 " $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
-- enable_reconnect
-- source include/wait_until_connected_again.inc
--disable_warnings
SELECT @@GLOBAL.Host_Cache_Size;
--echo 1 Expected
#set @Default_host_cache_size=(select if(if(@@global.max_connections<500,128+@@global.max_connections,128+@@global.max_connections+floor((@@global.max_connections-500)/20))>2000,2000,if(@@global.max_connections<500,128+@@global.max_connections,128+@@global.max_connections+floor((@@global.max_connections-500)/20))));
set @Default_host_cache_size=128;
SET @@GLOBAL.Host_Cache_Size=DEFAULT;
select @@global.Host_Cache_Size=@Default_host_cache_size;
--echo 1 Expected
--echo '#---------------------WL6372_VAR_6_03----------------------#'
####################################################################
# Checking Value can be set - Dynamic #
####################################################################
--error ER_GLOBAL_VARIABLE
SET @@local.Host_Cache_Size=1;
--echo Expected error 'Global variable'
--error ER_GLOBAL_VARIABLE
SET @@session.Host_Cache_Size=1;
--echo Expected error 'Global variable'
SET @@GLOBAL.Host_Cache_Size=1;
SET @@GLOBAL.Host_Cache_Size=DEFAULT;
SELECT COUNT(@@GLOBAL.Host_Cache_Size);
--echo 1 Expected
select @@global.Host_Cache_Size=@Default_host_cache_size;
--echo 1 Expected
--echo '#---------------------WL6372_VAR_6_04----------------------#'
#################################################################
# Check if the value in GLOBAL Table matches value in variable #
#################################################################
SELECT @@GLOBAL.Host_Cache_Size = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='Host_Cache_Size';
--echo 1 Expected
SELECT COUNT(@@GLOBAL.Host_Cache_Size);
--echo 1 Expected
SELECT COUNT(VARIABLE_VALUE)
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='Host_Cache_Size';
--echo 1 Expected
--echo '#---------------------WL6372_VAR_6_05----------------------#'
################################################################################
# Checking Variable Scope #
################################################################################
SELECT @@Host_Cache_Size = @@GLOBAL.Host_Cache_Size;
--echo 1 Expected
--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
SELECT COUNT(@@local.Host_Cache_Size);
--echo Expected error 'Variable is a GLOBAL variable'
--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
SELECT COUNT(@@SESSION.Host_Cache_Size);
--echo Expected error 'Variable is a GLOBAL variable'
SELECT COUNT(@@GLOBAL.Host_Cache_Size);
--echo 1 Expected
--Error ER_BAD_FIELD_ERROR
SELECT Host_Cache_Size = @@SESSION.Host_Cache_Size;
--echo Expected error 'Unknown column Host_Cache_Size in field list'
SET @@GLOBAL.Host_Cache_Size=DEFAULT;