From d88846fab49c08fdd423833d18b0e6e035aa4dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 31 May 2019 11:04:45 +0300 Subject: [PATCH] MXS-2515: Add KILL QUERY test case The test checks that queries are killed properly. --- maxscale-system-test/CMakeLists.txt | 3 ++ maxscale-system-test/kill_query.cpp | 50 +++++++++++++++++++++++++++++ maxscale-system-test/mariadb_func.h | 5 +++ 3 files changed, 58 insertions(+) create mode 100644 maxscale-system-test/kill_query.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index fe6f107dc..ec163fda5 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -204,6 +204,9 @@ add_test_executable(maxctrl_basic.cpp maxctrl_basic maxctrl_basic LABELS maxctrl # MXS-2167: Monitors should be able to use extra_port add_test_executable(mxs2167_extra_port.cpp mxs2167_extra_port mxs2167_extra_port LABELS REPL_BACKEND) +# Test KILL QUERY functionality +add_test_executable(kill_query.cpp kill_query replication LABELS REPL_BACKEND) + ############################################ # BEGIN: Tests that require GTID # ############################################ diff --git a/maxscale-system-test/kill_query.cpp b/maxscale-system-test/kill_query.cpp new file mode 100644 index 000000000..d03c37b09 --- /dev/null +++ b/maxscale-system-test/kill_query.cpp @@ -0,0 +1,50 @@ +/** + * Test KILL QUERY functionality + */ + +#include "testconnections.h" + +int main(int argc, char* argv[]) +{ + TestConnections test(argc, argv); + + auto conn = test.maxscales->rwsplit(); + conn.connect(); + conn.query("CREATE OR REPLACE TABLE test.t1 (id LONGTEXT)"); + + for (int x = 0; x < 10; x++) + { + conn.query("INSERT INTO test.t1 VALUES (REPEAT('a', 5000000))"); + } + + for (int i = 0; i < 3; i++) + { + auto a = test.maxscales->rwsplit(); + auto b = test.maxscales->rwsplit(); + test.expect(a.connect() && b.connect(), "Connections should work"); + + auto id = a.thread_id(); + + test.set_timeout(15); + std::thread thr( + [&]() { + // The ALTER should take longer than 15 seconds to complete so that a KILL is required to + // interrupt it. + test.expect(!a.query("ALTER TABLE test.t1 FORCE"), "ALTER should fail"); + + const char* expected = "Query execution was interrupted"; + test.expect(strstr(a.error(), expected), + "Alter should fail with '%s' but it failed with '%s'", + expected, a.error()); + }); + + test.expect(b.query("KILL QUERY " + std::to_string(id)), "KILL QUERY failed: %s", b.error()); + thr.join(); + + test.stop_timeout(); + } + + conn.query("DROP TABLE test.t1"); + + return test.global_result; +} diff --git a/maxscale-system-test/mariadb_func.h b/maxscale-system-test/mariadb_func.h index e53bad9b4..e4586f399 100644 --- a/maxscale-system-test/mariadb_func.h +++ b/maxscale-system-test/mariadb_func.h @@ -342,6 +342,11 @@ public: return change_user(m_user, m_pw, m_db); } + uint32_t thread_id() const + { + return mysql_thread_id(m_conn); + } + private: std::string m_host; int m_port;