1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00
Files
mariadb/mysql-test/suite/innodb/t/auto_increment_lock_mode.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

60 lines
1.7 KiB
Plaintext

--source include/have_innodb.inc
CREATE TABLE t1(a TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t2(a TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t3(a TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t4(a TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t5(a TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t6(a SERIAL, b INT) ENGINE=InnoDB;
DELIMITER $$;
CREATE FUNCTION p1() RETURNS INT
BEGIN
INSERT INTO t1() VALUES();
INSERT INTO t2() VALUES();
INSERT INTO t3() VALUES();
INSERT INTO t4() VALUES();
INSERT INTO t5() VALUES();
RETURN 1;
END$$
DELIMITER ;$$
INSERT INTO t6(b) SELECT p1();
UPDATE t1,t2,t3,t4,t5 SET t1.a=2,t2.a=2,t3.a=2,t4.a=2,t5.a=2;
SELECT * FROM t1;
--connect(con1,localhost,root,,)
let $ID1= `SELECT @id := CONNECTION_ID()`;
--connect(con2,localhost,root,,)
let $ID2= `SELECT @id := CONNECTION_ID()`;
--connect(con3,localhost,root,,)
let $ID3= `SELECT @id := CONNECTION_ID()`;
--connection con1
send INSERT INTO t6(b) SELECT SLEEP(p1());
--connection con2
send INSERT INTO t6(b) SELECT SLEEP(p1());
--connection con3
send UPDATE t1,t2,t3,t4,t5 SET t1.a=0,t2.a=0,t3.a=0,t4.a=0,t5.a=0
WHERE t1.a=2 AND t2.a=2 AND t3.a=2 AND t4.a=2 AND t5.a=2;
--connection default
evalp KILL QUERY $ID1;
evalp KILL QUERY $ID2;
evalp KILL QUERY $ID3;
--connection con1
--error 0,ER_QUERY_INTERRUPTED,ER_AUTOINC_READ_FAILED
--reap
--disconnect con1
--connection con2
--error 0,ER_QUERY_INTERRUPTED,ER_AUTOINC_READ_FAILED
--reap
--disconnect con2
--connection con3
--error 0,ER_QUERY_INTERRUPTED,ER_AUTOINC_READ_FAILED
--reap
--disconnect con3
--connection default
DROP FUNCTION p1;
DROP TABLE t1,t2,t3,t4,t5,t6;