From f39f27cd7b606f8a691767ecc8f436322437b9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 28 Jan 2019 12:40:32 +0200 Subject: [PATCH] MXS-2295: Session command loop test case Test executes various session commands in a loop and makes sure a COM_CHANGE_USER resets the history. --- maxscale-system-test/CMakeLists.txt | 3 + ...cale.cnf.template.mxs2295_change_user_loop | 50 ++++++++++++++ maxscale-system-test/mariadb_func.h | 10 +++ .../mxs2295_change_user_loop.cpp | 66 +++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100755 maxscale-system-test/cnf/maxscale.cnf.template.mxs2295_change_user_loop create mode 100644 maxscale-system-test/mxs2295_change_user_loop.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index cfce1f6e3..29f6f1b92 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -915,6 +915,9 @@ add_test_executable(mxs2111_auth_string.cpp mxs2111_auth_string replication LABE # MXS-2115: Automatic version_string detection add_test_executable(mxs2115_version_string.cpp mxs2115_version_string replication LABELS REPL_BACKEND) +# MXS-2295: COM_CHANGE_USER does not clear out session command history +add_test_executable(mxs2295_change_user_loop.cpp mxs2295_change_user_loop mxs2295_change_user_loop LABELS REPL_BACKEND) + ############################################ # BEGIN: binlogrouter and avrorouter tests # ############################################ diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.mxs2295_change_user_loop b/maxscale-system-test/cnf/maxscale.cnf.template.mxs2295_change_user_loop new file mode 100755 index 000000000..7b1b8a1db --- /dev/null +++ b/maxscale-system-test/cnf/maxscale.cnf.template.mxs2295_change_user_loop @@ -0,0 +1,50 @@ +[maxscale] +threads=###threads### +log_info=1 + +[server1] +type=server +address=###node_server_IP_1### +port=###node_server_port_1### +protocol=MySQLBackend + +[server2] +type=server +address=###node_server_IP_2### +port=###node_server_port_2### +protocol=MySQLBackend + +[server3] +type=server +address=###node_server_IP_3### +port=###node_server_port_3### +protocol=MySQLBackend + +[server4] +type=server +address=###node_server_IP_4### +port=###node_server_port_4### +protocol=MySQLBackend + +[MySQL Monitor] +type=monitor +module=mysqlmon +servers=server1,server2,server3,server4 +user=maxskysql +password=skysql +monitor_interval=1000 + +[RW Split Router] +type=service +router=readwritesplit +servers=server1,server2,server3,server4 +user=maxskysql +password=skysql +max_sescmd_history=20 +disable_sescmd_history=false + +[RW Split Listener] +type=listener +service=RW Split Router +protocol=MySQLClient +port=4006 diff --git a/maxscale-system-test/mariadb_func.h b/maxscale-system-test/mariadb_func.h index df9d86bac..794ff03a4 100644 --- a/maxscale-system-test/mariadb_func.h +++ b/maxscale-system-test/mariadb_func.h @@ -334,6 +334,16 @@ public: return mysql_error(m_conn); } + bool change_user(std::string user, std::string pw, std::string db = "test") + { + return mysql_change_user(m_conn, user.c_str(), pw.c_str(), db.c_str()) == 0; + } + + bool reset_connection() + { + return change_user(m_user, m_pw, m_db); + } + private: std::string m_host; int m_port; diff --git a/maxscale-system-test/mxs2295_change_user_loop.cpp b/maxscale-system-test/mxs2295_change_user_loop.cpp new file mode 100644 index 000000000..62e963f98 --- /dev/null +++ b/maxscale-system-test/mxs2295_change_user_loop.cpp @@ -0,0 +1,66 @@ +/** + * MXS-2295: COM_CHANGE_USER does not clear out session command history + * https://jira.mariadb.org/browse/MXS-2295 + */ + +#include "testconnections.h" + +int main(int argc, char *argv[]) +{ + TestConnections test(argc, argv); + + + Connection conn = test.maxscales->rwsplit(); + test.expect(conn.connect(), "Connection failed: %s", conn.error()); + + for (int i = 0; i <= 300 && test.global_result == 0; i++) + { + if (i % 50 == 0) + { + test.tprintf("Iteration: %d", i); + } + + test.set_timeout(60); + + // Interleaved session commands, reads and "writes" (`SELECT @@last_insert_id` is treated as a master-only read) + test.expect(conn.query("SET @a = 1"), "Query failed: %s", conn.error()); + test.expect(conn.query("USE test"), "Query failed: %s", conn.error()); + test.expect(conn.query("SET SQL_MODE=''"), "Query failed: %s", conn.error()); + test.expect(conn.query("USE test"), "Query failed: %s", conn.error()); + test.expect(conn.query("SELECT @@last_insert_id"), "Query failed: %s", conn.error()); + test.expect(conn.query("SELECT 1"), "Query failed: %s", conn.error()); + test.expect(conn.query("USE test"), "Query failed: %s", conn.error()); + test.expect(conn.query("SELECT 1"), "Query failed: %s", conn.error()); + + // User variable inside transaction + test.expect(conn.query("SET @a = 123"), "Query failed: %s", conn.error()); + test.expect(conn.query("BEGIN"), "Query failed: %s", conn.error()); + Row row = conn.row("SELECT @a"); + test.expect(!row.empty() && row[0] == "123", "Invalid contents in user variable inside RW trx"); + test.expect(conn.query("COMMIT"), "Query failed: %s", conn.error()); + + // User variable outside transaction + test.expect(conn.query("SET @a = 321"), "Query failed: %s", conn.error()); + row = conn.row("SELECT @a"); + test.expect(!row.empty() && row[0] == "321", "Invalid contents in user variable outside trx"); + + // User variable inside read-only transaction + test.expect(conn.query("SET @a = 456"), "Query failed: %s", conn.error()); + test.expect(conn.query("START TRANSACTION READ ONLY"), "Query failed: %s", conn.error()); + row = conn.row("SELECT @a"); + test.expect(!row.empty() && row[0] == "456", "Invalid contents in user variable inside RO trx"); + test.expect(conn.query("COMMIT"), "Query failed: %s", conn.error()); + + test.expect(conn.query("PREPARE ps FROM 'SELECT 1'"), "PREPARE failed: %s", conn.error()); + row = conn.row("EXECUTE ps"); + test.expect(!row.empty() && row[0] == "1", "Invalid contents in PS result"); + test.expect(conn.query("DEALLOCATE PREPARE ps"), "DEALLOCATE failed: %s", conn.error()); + + test.expect(conn.reset_connection(), "Connection reset failed: %s", conn.error()); + } + + test.log_excludes(0, "Router session exceeded session command history limit"); + test.log_includes(0, "Resetting session command history"); + + return test.global_result; +}