mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 21:55:03 +02:00

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
135 lines
4 KiB
Text
135 lines
4 KiB
Text
# Last modification:
|
|
# 2009-01-19 H.Hunger Fix Bug#39108 main.wait_timeout fails sporadically
|
|
# - Increase wait timeout to 2 seconds
|
|
# - Eliminated the corresponding opt file,
|
|
# set global wait timeout within the test.
|
|
# - Replaced sleeps by wait condition
|
|
# - Minor improvements
|
|
###############################################################################
|
|
# These tests cannot run with the embedded server
|
|
-- source include/not_embedded.inc
|
|
#-- source include/one_thread_per_connection.inc
|
|
|
|
#
|
|
# Bug#8731 wait_timeout does not work on Mac OS X
|
|
#
|
|
|
|
let $start_value= `SELECT @@global.wait_timeout`;
|
|
SET @@global.wait_timeout= 2;
|
|
disconnect default;
|
|
|
|
# Connect with another connection and reset counters
|
|
connect (wait_con,localhost,root,,test,,);
|
|
connection wait_con;
|
|
--disable_query_log
|
|
SET SESSION wait_timeout=100;
|
|
let $retries=300;
|
|
SET @aborted_clients= 0;
|
|
--enable_query_log
|
|
|
|
# Disable reconnect and do the query
|
|
connect (default,localhost,root,,test,,);
|
|
connection default;
|
|
--echo --disable_reconnect;
|
|
--disable_reconnect
|
|
SELECT 1;
|
|
|
|
# Switch to wait_con and wait until server has aborted the connection
|
|
connection wait_con;
|
|
--disable_query_log
|
|
while (!`select @aborted_clients`)
|
|
{
|
|
real_sleep 0.1;
|
|
let $aborted_clients = `SHOW STATUS LIKE 'aborted_clients'`;
|
|
eval SET @aborted_clients= SUBSTRING('$aborted_clients', 16)+0;
|
|
|
|
dec $retries;
|
|
if (!$retries)
|
|
{
|
|
die Failed to detect that client has been aborted;
|
|
}
|
|
}
|
|
--enable_query_log
|
|
# The server has disconnected, add small sleep to make sure
|
|
# the disconnect has reached client
|
|
let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist;
|
|
--source include/wait_condition.inc
|
|
connection default;
|
|
# When the connection is closed in this way, the error code should
|
|
# be consistent see Bug#2845 for an explanation
|
|
# depending on platform/client, either errno 2006 or 2013 can occur below
|
|
--error 2006,2013,5014
|
|
SELECT 2;
|
|
--echo --enable_reconnect;
|
|
--enable_reconnect
|
|
SELECT 3;
|
|
# Disconnect so that we will not be confused by a future abort from this
|
|
# connection.
|
|
disconnect default;
|
|
|
|
#
|
|
# Do the same test as above on a TCP connection
|
|
# (which we get by specifying an ip adress)
|
|
|
|
# Connect with another connection and reset counters
|
|
connection wait_con;
|
|
--disable_query_log
|
|
FLUSH STATUS; # Reset counters
|
|
let $retries=300;
|
|
SET @aborted_clients= 0;
|
|
--enable_query_log
|
|
|
|
connect (con1,127.0.0.1,root,,test,$MASTER_MYPORT,);
|
|
--echo --disable_reconnect;
|
|
--disable_reconnect
|
|
SELECT 1;
|
|
|
|
# Switch to wait_con and wait until server has aborted the connection
|
|
connection wait_con;
|
|
--disable_query_log
|
|
while (!`select @aborted_clients`)
|
|
{
|
|
real_sleep 0.1;
|
|
let $aborted_clients = `SHOW STATUS LIKE 'aborted_clients'`;
|
|
eval SET @aborted_clients= SUBSTRING('$aborted_clients', 16)+0;
|
|
|
|
dec $retries;
|
|
if (!$retries)
|
|
{
|
|
die Failed to detect that client has been aborted;
|
|
}
|
|
}
|
|
--enable_query_log
|
|
# The server has disconnected, add small sleep to make sure
|
|
# the disconnect has reached client
|
|
let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist;
|
|
--source include/wait_condition.inc
|
|
disconnect wait_con;
|
|
|
|
connection con1;
|
|
# When the connection is closed in this way, the error code should
|
|
# be consistent see Bug#2845 for an explanation
|
|
# depending on platform/client, either errno 2006 or 2013 can occur below
|
|
--error 2006,2013,5014
|
|
SELECT 2;
|
|
--echo --enable_reconnect;
|
|
--enable_reconnect
|
|
SELECT 3;
|
|
--replace_result $start_value <start_value>
|
|
eval SET @@global.wait_timeout= $start_value;
|
|
disconnect con1;
|
|
|
|
connect (default,localhost,root,,test,,);
|
|
|
|
#
|
|
# MDEV-7775 Wrong error message (Unknown error) when idle sessions are killed after wait_timeout
|
|
#
|
|
set global log_warnings=2;
|
|
connect (foo,localhost,root);
|
|
set @@wait_timeout=1;
|
|
sleep 2;
|
|
connection default;
|
|
let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err;
|
|
let SEARCH_PATTERN= Aborted.*Got timeout reading communication packets;
|
|
source include/search_pattern_in_file.inc;
|
|
set global log_warnings=@@log_warnings;
|