MXS-2515: Add KILL QUERY test case

The test checks that queries are killed properly.
This commit is contained in:
Markus Mäkelä 2019-05-31 11:04:45 +03:00
parent e9c652555d
commit d88846fab4
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
3 changed files with 58 additions and 0 deletions

View File

@ -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 #
############################################

View File

@ -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;
}

View File

@ -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;