summaryrefslogtreecommitdiff
path: root/mysql-test/t/connect.test
diff options
context:
space:
mode:
authorunknown <anozdrin/alik@quad.>2008-03-17 14:26:00 +0300
committerunknown <anozdrin/alik@quad.>2008-03-17 14:26:00 +0300
commitc1e69a77a6f6563214b5f5e8813db423c4f3a04c (patch)
treedbed4b209c7f0db9b9c6015b42e71bd1761897b8 /mysql-test/t/connect.test
parent30d644f859ee65748f12e3861abaf1fbb2c3b2c7 (diff)
downloadmariadb-git-c1e69a77a6f6563214b5f5e8813db423c4f3a04c.tar.gz
Avoid races in connect.test.
The problem was in a test case for Bug33507: - when the number of active connections reaches the limit, the server accepts only root connections. That's achieved by accepting a connection, negotiating with the client and checking user credentials. If it is not SUPER, the connection is dropped. - when the server accepts connection, it increases the counter; - when the server drops connection, it decreases the counter; - the race was in between of decreasing the counter and accepting new connection: - max_user_connections = 2; - 2 oridinary user connections accepted; - extra user connection is establishing; - server checked user credentials, and sent 'Too many connections' error; - the client receives the error and establishes extra SUPER user connection; - the server however didn't decrease the counter (the extra user connection still is "alive" in the server) -- so, the new SUPER-user connection, will be dropped, because it exceeds (max_user_connections + 1). The fix is to implement "safe connect", which makes several attempts to connect and use it in the test script. mysql-test/r/connect.result: Update test file. mysql-test/t/connect.test: Avoid races in connect.test. mysql-test/include/connect2.inc: Auxiliary routine to establish a connection reliably.
Diffstat (limited to 'mysql-test/t/connect.test')
-rw-r--r--mysql-test/t/connect.test80
1 files changed, 34 insertions, 46 deletions
diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test
index c8b69a050ba..0893bf9ad18 100644
--- a/mysql-test/t/connect.test
+++ b/mysql-test/t/connect.test
@@ -114,106 +114,94 @@ drop table t1;
--echo # -- End of 4.1 tests
--echo # ------------------------------------------------------------------
+###########################################################################
+
--echo
--echo # -- Bug#33507: Event scheduler creates more threads than max_connections
--echo # -- which results in user lockout.
---echo
+--echo
GRANT USAGE ON *.* TO mysqltest_u1@localhost;
# NOTE: if the test case fails sporadically due to spurious connections,
# consider disabling all users.
--echo
-
let $saved_max_connections = `SELECT @@global.max_connections`;
-
SET GLOBAL max_connections = 3;
SET GLOBAL event_scheduler = ON;
--echo
---echo # -- Waiting for old connections to close...
-let $wait_condition =
- SELECT COUNT(*) = 1
- FROM information_schema.processlist
- WHERE db = 'test';
---source include/wait_condition.inc
-
---echo
+--echo # -- Waiting for Event Scheduler to start...
let $wait_condition =
SELECT COUNT(*) = 1
FROM information_schema.processlist
WHERE user = 'event_scheduler';
--source include/wait_condition.inc
---echo
+--echo
--echo # -- Disconnecting default connection...
--disconnect default
--echo
--echo # -- Check that we allow exactly three user connections, no matter how
--echo # -- many threads are running.
---echo
+--echo
--echo # -- Connecting (1)...
---connect (con_1,localhost,mysqltest_u1)
+let $con_name = con_1;
+let $con_user_name = mysqltest_u1;
+--source include/connect2.inc
--echo
---echo # -- Waiting for root connection to close...
-let $wait_condition =
- SELECT COUNT(*) = 1
- FROM information_schema.processlist
- WHERE db = 'test';
---source include/wait_condition.inc
---echo
-
--echo # -- Connecting (2)...
---connect (con_2,localhost,mysqltest_u1)
+let $con_name = con_2;
+let $con_user_name = mysqltest_u1;
+--source include/connect2.inc
+--echo
--echo # -- Connecting (3)...
---connect (con_3,localhost,mysqltest_u1)
-
---echo # -- Connecting (4)...
---disable_query_log
---error ER_CON_COUNT_ERROR
---connect (con_4,localhost,mysqltest_u1)
---enable_query_log
+let $con_name = con_3;
+let $con_user_name = mysqltest_u1;
+--source include/connect2.inc
--echo
---echo # -- Waiting for the last connection to close...
-let $wait_condition =
- SELECT COUNT(*) = 3
- FROM information_schema.processlist
- WHERE db = 'test';
---source include/wait_condition.inc
+--echo # -- Connecting (4) [should fail]...
+let $con_name = con_4;
+let $con_user_name = mysqltest_u1;
+let $wait_timeout = 5;
+--source include/connect2.inc
--echo
--echo # -- Check that we allow one extra SUPER-user connection.
---echo
+--echo
--echo # -- Connecting super (1)...
---connect (con_super_1,localhost,root)
+let $con_name = con_super_1;
+let $con_user_name = root;
+--source include/connect2.inc
---echo # -- Connecting super (2)...
---disable_query_log
---error ER_CON_COUNT_ERROR
---connect (con_super_2,localhost,root)
---enable_query_log
+--echo
+--echo # -- Connecting super (2) [should fail]...
+let $con_name = con_super_2;
+let $con_user_name = root;
+let $wait_timeout = 5;
+--source include/connect2.inc
--echo
-# Ensure that we have Event Scheduler thread, 3 ordinary user connections and
-# one extra super-user connection.
+--echo # -- Ensure that we have Event Scheduler thread, 3 ordinary user
+--echo # -- connections and one extra super-user connection.
SELECT user FROM information_schema.processlist ORDER BY id;
--echo
--echo # -- Resetting variables...
-
--eval SET GLOBAL max_connections = $saved_max_connections
--echo
--echo # -- Stopping Event Scheduler...
SET GLOBAL event_scheduler = OFF;
+--echo
--echo # -- Waiting for Event Scheduler to stop...
let $wait_condition =
SELECT COUNT(*) = 0