mirror of
https://github.com/MariaDB/server.git
synced 2025-08-22 18:31:36 +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
67 lines
1.7 KiB
Text
67 lines
1.7 KiB
Text
#
|
|
# Tests that require transactions
|
|
#
|
|
-- source include/not_embedded.inc
|
|
-- source include/have_innodb.inc
|
|
--disable_warnings
|
|
drop database if exists events_test;
|
|
drop database if exists mysqltest_db2;
|
|
--enable_warnings
|
|
create database events_test;
|
|
use events_test;
|
|
|
|
#
|
|
# Privilege checks
|
|
#
|
|
create user mysqltest_user1@localhost;
|
|
grant create, insert, select, delete on mysqltest_db2.*
|
|
to mysqltest_user1@localhost;
|
|
create database mysqltest_db2;
|
|
connect (conn1,localhost,mysqltest_user1,,mysqltest_db2);
|
|
set autocommit=off;
|
|
# Sanity check
|
|
select @@autocommit;
|
|
create table t1 (a varchar(255)) engine=innodb;
|
|
# Not enough privileges to CREATE EVENT
|
|
begin work;
|
|
insert into t1 (a) values ("OK: create event: insufficient privileges");
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
create event e1 on schedule every 1 day do select 1;
|
|
rollback work;
|
|
select * from t1;
|
|
delete from t1;
|
|
commit work;
|
|
# Not enough privileges to ALTER EVENT
|
|
begin work;
|
|
insert into t1 (a) values ("OK: alter event: insufficient privileges");
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
alter event e1 on schedule every 1 day do select 1;
|
|
rollback work;
|
|
select * from t1;
|
|
delete from t1;
|
|
commit work;
|
|
# Not enough privileges to DROP EVENT
|
|
begin work;
|
|
insert into t1 (a) values ("OK: drop event: insufficient privileges");
|
|
--error ER_DBACCESS_DENIED_ERROR
|
|
drop event e1;
|
|
rollback work;
|
|
select * from t1;
|
|
delete from t1;
|
|
commit work;
|
|
# Cleanup
|
|
disconnect conn1;
|
|
connection default;
|
|
drop user mysqltest_user1@localhost;
|
|
drop database mysqltest_db2;
|
|
|
|
#
|
|
# Cleanup
|
|
#
|
|
let $wait_condition=
|
|
select count(*) = 0 from information_schema.processlist
|
|
where db='events_test' and command = 'Connect' and user=current_user();
|
|
--source include/wait_condition.inc
|
|
|
|
drop database events_test;
|
|
|