diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index f54a39bdf..6eb9ceca2 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -596,6 +596,9 @@ add_test_executable(mxs1476.cpp mxs1476 mxs1476 LABELS GALERA_BACKEND) # https://jira.mariadb.org/browse/MXS-1503 add_test_executable(mxs1503_master_reconnection.cpp mxs1503_master_reconnection mxs1503_master_reconnection LABELS REPL_BACKEND) +# Master reconnection with session commands +add_test_executable(mxs1503_queued_sescmd.cpp mxs1503_queued_sescmd mxs1503_master_reconnection LABELS REPL_BACKEND) + # MXS-1509: Show correct server state for multisource replication # https://jira.mariadb.org/browse/MXS-1509 add_test_executable(mxs1509.cpp mxs1509 mxs1509 LABELS REPL_BACKEND) diff --git a/maxscale-system-test/mxs1503_queued_sescmd.cpp b/maxscale-system-test/mxs1503_queued_sescmd.cpp new file mode 100644 index 000000000..6a94d0506 --- /dev/null +++ b/maxscale-system-test/mxs1503_queued_sescmd.cpp @@ -0,0 +1,58 @@ +/** + * MXS-1503: Test master reconnection with session command history + * + * https://jira.mariadb.org/browse/MXS-1503 + */ +#include "testconnections.h" +#include +#include +#include + +using std::cout; +using std::endl; + +int main(int argc, char** argv) +{ + TestConnections test(argc, argv); + + auto query = [&test](std::string q) + { + return execute_query_silent(test.maxscales->conn_rwsplit[0], q.c_str()); + }; + + auto check_result = [&test](std::string name, std::string res) + { + std::string query = "SELECT " + name; + char value[1024]; + return find_field(test.maxscales->conn_rwsplit[0], query.c_str(), name.c_str(), value) == 0 && + res == value; + }; + + test.maxscales->connect(); + test.assert(query("DROP TABLE IF EXISTS test.t1;") == 0, "DROP TABLE should work."); + test.assert(query("CREATE TABLE test.t1 (id INT);") == 0, "CREATE TABLE should work."); + + // Execute session commands so that the history is not empty + cout << "Setting user variables" << endl; + test.assert(query("SET @a = 1") == 0, "First session command should work."); + test.assert(query("USE test") == 0, "Second session command should work."); + test.assert(query("SET @b = 2") == 0, "Third session command should work."); + + // Block the master to trigger reconnection + cout << "Blocking master" << endl; + test.repl->block_node(0); + sleep(10); + cout << "Unblocking master" << endl; + test.repl->unblock_node(0); + sleep(10); + + // Check that inserts work + cout << "Selecting user variables" << endl; + test.set_timeout(15); + test.assert(query("INSERT INTO test.t1 VALUES (1)") == 0, "Write should work after unblocking master"); + test.assert(check_result("@a", "1"), "@a should be 1"); + test.assert(check_result("@b", "2"), "@b should be 2"); + query("DROP TABLE test.t1"); + + return test.global_result; +}