From 6ca51431415755ea5478d810a550f0cf4f9654e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 11 Jun 2019 14:44:51 +0300 Subject: [PATCH] Make kill_query more robust The test now uses an infinite loop in the SQL to make sure the execution is interrupted. --- maxscale-system-test/kill_query.cpp | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/maxscale-system-test/kill_query.cpp b/maxscale-system-test/kill_query.cpp index d03c37b09..c815033e2 100644 --- a/maxscale-system-test/kill_query.cpp +++ b/maxscale-system-test/kill_query.cpp @@ -8,15 +8,6 @@ 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(); @@ -25,12 +16,21 @@ int main(int argc, char* argv[]) 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 + const char* query = + "BEGIN NOT ATOMIC " + " DECLARE v1 INT DEFAULT 5; " + " CREATE OR REPLACE TABLE test.t1(id INT); " + " WHILE v1 <> 0 DO " + " INSERT INTO test.t1 VALUES (1); " + " SET v1 = (SELECT COUNT(*) FROM test.t1); " + " END WHILE;" + "END"; + + // 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"); + test.expect(!a.query(query), "Query should fail"); const char* expected = "Query execution was interrupted"; test.expect(strstr(a.error(), expected), @@ -38,12 +38,17 @@ int main(int argc, char* argv[]) expected, a.error()); }); + // Wait for a few seconds to make sure the other thread has started executing the query before killing it. + sleep(5); test.expect(b.query("KILL QUERY " + std::to_string(id)), "KILL QUERY failed: %s", b.error()); - thr.join(); + test.set_timeout(15); + thr.join(); test.stop_timeout(); } + auto conn = test.maxscales->rwsplit(); + conn.connect(); conn.query("DROP TABLE test.t1"); return test.global_result;