Commit 4a81c0df authored by kroki@mysql.com's avatar kroki@mysql.com

In test for bug#15933 we have to wait for all disconnects to finish to avoid

a race between updating and checking Max_used_connections.  This is done in
a loop until either disconnect finished or timeout expired.  In a latter case
the test will fail.
parent 6222ca41
......@@ -26,20 +26,20 @@ Last_query_cost 0.000000
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 3
Max_used_connections 1
SET @save_thread_cache_size=@@thread_cache_size;
SET GLOBAL thread_cache_size=3;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 5
Max_used_connections 3
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 4
Max_used_connections 2
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 5
Max_used_connections 3
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 6
Max_used_connections 4
SET GLOBAL thread_cache_size=@save_thread_cache_size;
......@@ -36,6 +36,10 @@ reap;
show status like 'Table_lock%';
drop table t1;
disconnect con2;
disconnect con1;
connection default;
# End of 4.1 tests
#
......@@ -60,48 +64,81 @@ show status like 'last_query_cost';
# taking a thread from the cache as well as when creating new threads
#
# Previous test uses con1, con2. If we disconnect them, there will be
# a race on when exactly this will happen, so we better leave them as
# is.
connection default;
# Wait for at most $disconnect_timeout seconds for disconnects to finish.
let $disconnect_timeout = 10;
# Reset max_used_connections from previous tests.
# Wait for any previous disconnects to finish.
FLUSH STATUS;
--disable_query_log
--disable_result_log
eval SET @wait_left = $disconnect_timeout;
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`;
while ($wait_more)
{
sleep 1;
FLUSH STATUS;
SET @wait_left = @wait_left - 1;
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
let $wait_more = `SELECT @max_used_connections != 1 && @wait_left > 0`;
}
--enable_query_log
--enable_result_log
# Prerequisite.
SHOW STATUS LIKE 'max_used_connections';
# Save original setting.
SET @save_thread_cache_size=@@thread_cache_size;
SET GLOBAL thread_cache_size=3;
connect (con3,localhost,root,,);
connect (con4,localhost,root,,);
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
connection con3;
disconnect con4;
connection con1;
disconnect con2;
# Check that max_used_connections still reflects maximum value.
SHOW STATUS LIKE 'max_used_connections';
# Check that after flush max_used_connections equals to current number
# of connections.
# of connections. First wait for previous disconnect to finish.
FLUSH STATUS;
--disable_query_log
--disable_result_log
eval SET @wait_left = $disconnect_timeout;
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`;
while ($wait_more)
{
sleep 1;
FLUSH STATUS;
SET @wait_left = @wait_left - 1;
let $max_used_connections = `SHOW STATUS LIKE 'max_used_connections'`;
eval SET @max_used_connections = SUBSTRING('$max_used_connections', 21)+0;
let $wait_more = `SELECT @max_used_connections != 2 && @wait_left > 0`;
}
--enable_query_log
--enable_result_log
# Check that we don't count disconnected thread any longer.
SHOW STATUS LIKE 'max_used_connections';
# Check that max_used_connections is updated when cached thread is
# reused...
connect (con4,localhost,root,,);
connect (con2,localhost,root,,);
SHOW STATUS LIKE 'max_used_connections';
# ...and when new thread is created.
connect (con5,localhost,root,,);
connect (con3,localhost,root,,);
SHOW STATUS LIKE 'max_used_connections';
# Restore original setting.
connection default;
SET GLOBAL thread_cache_size=@save_thread_cache_size;
disconnect con5;
disconnect con4;
disconnect con3;
disconnect con2;
disconnect con1;
......
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