From 18b0d3575e8b531197d848ea66773f90a5225577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sun, 24 Sep 2017 20:03:02 +0300 Subject: [PATCH] Speed up binlog tests The binlogrouter tests can safely use the sync_slaves functionality of the test framework as long as a sensible timeout is used. Cleaned up the tests by removing redundant code and allocating classes from the stack thus removing the need to handle memory allocation. --- maxscale-system-test/binlog_semisync.cpp | 92 ++++++++++-------------- maxscale-system-test/setup_binlog.cpp | 33 +++------ maxscale-system-test/test_binlog_fnc.cpp | 25 +++---- 3 files changed, 58 insertions(+), 92 deletions(-) diff --git a/maxscale-system-test/binlog_semisync.cpp b/maxscale-system-test/binlog_semisync.cpp index 14ef7d558..d3e66cb8b 100644 --- a/maxscale-system-test/binlog_semisync.cpp +++ b/maxscale-system-test/binlog_semisync.cpp @@ -13,66 +13,48 @@ int main(int argc, char *argv[]) { + TestConnections test(argc, argv); - TestConnections * Test = new TestConnections(argc, argv); - Test->tprintf("Test object initialized"); - Test->set_timeout(3000); - Test->tprintf("Trying to connect to backend"); + test.repl->connect(); + test.binlog_cmd_option = 1; + test.start_binlog(); + test.repl->connect(); + test.tprintf("install semisync plugin"); + execute_query(test.repl->nodes[0], + (char *) "INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';"); - if (Test->repl->connect() == 0) - { - Test->tprintf("DROP TABLE t1"); - execute_query(Test->repl->nodes[0], (char *) "DROP TABLE IF EXISTS t1;"); + test.tprintf("Reconnect"); + test.repl->close_connections(); + test.repl->connect(); + test.tprintf("SET GLOBAL rpl_semi_sync_master_enabled = 1;"); + execute_query(test.repl->nodes[0], (char *) "SET GLOBAL rpl_semi_sync_master_enabled = 1;"); + test.repl->close_connections(); + test_binlog(&test); - Test->repl->close_connections(); - sleep(5); + test.repl->connect(); + test.tprintf("SET GLOBAL rpl_semi_sync_master_enabled = 0;"); + execute_query(test.repl->nodes[0], (char *) "SET GLOBAL rpl_semi_sync_master_enabled = 0;"); + test.repl->close_connections(); + test_binlog(&test); - Test->binlog_cmd_option = 1; - Test->start_binlog(); - Test->repl->connect(); - Test->tprintf("install semisync plugin"); - execute_query(Test->repl->nodes[0], - (char *) "INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';"); + test.repl->connect(); + test.tprintf("uninstall semisync plugin"); + execute_query(test.repl->nodes[0], (char *) "UNINSTALL PLUGIN rpl_semi_sync_master;"); + test.tprintf("Reconnect"); + test.repl->close_connections(); + test.repl->connect(); + test.tprintf("SET GLOBAL rpl_semi_sync_master_enabled = 1;"); + execute_query(test.repl->nodes[0], (char *) "SET GLOBAL rpl_semi_sync_master_enabled = 1;"); + test.repl->close_connections(); + test_binlog(&test); - Test->tprintf("Reconnect"); - Test->repl->close_connections(); - Test->repl->connect(); - Test->tprintf("SET GLOBAL rpl_semi_sync_master_enabled = 1;"); - execute_query(Test->repl->nodes[0], (char *) "SET GLOBAL rpl_semi_sync_master_enabled = 1;"); - Test->repl->close_connections(); - test_binlog(Test); + test.repl->connect(); + test.tprintf("SET GLOBAL rpl_semi_sync_master_enabled = 0;"); + execute_query(test.repl->nodes[0], (char *) "SET GLOBAL rpl_semi_sync_master_enabled = 0;"); + test.repl->sync_slaves();; + test.repl->close_connections(); + test_binlog(&test); - Test->repl->connect(); - Test->tprintf("SET GLOBAL rpl_semi_sync_master_enabled = 0;"); - execute_query(Test->repl->nodes[0], (char *) "SET GLOBAL rpl_semi_sync_master_enabled = 0;"); - Test->repl->close_connections(); - test_binlog(Test); - - Test->repl->connect(); - Test->tprintf("uninstall semisync plugin"); - execute_query(Test->repl->nodes[0], (char *) "UNINSTALL PLUGIN rpl_semi_sync_master;"); - Test->tprintf("Reconnect"); - Test->repl->close_connections(); - Test->repl->connect(); - Test->tprintf("SET GLOBAL rpl_semi_sync_master_enabled = 1;"); - execute_query(Test->repl->nodes[0], (char *) "SET GLOBAL rpl_semi_sync_master_enabled = 1;"); - Test->repl->close_connections(); - test_binlog(Test); - - Test->repl->connect(); - Test->tprintf("SET GLOBAL rpl_semi_sync_master_enabled = 0;"); - execute_query(Test->repl->nodes[0], (char *) "SET GLOBAL rpl_semi_sync_master_enabled = 0;"); - sleep(10); - Test->repl->close_connections(); - test_binlog(Test); - } - else - { - Test->add_result(1, "Can't connect to backend"); - } - - int rval = Test->global_result; - delete Test; - return rval; + return test.global_result; } diff --git a/maxscale-system-test/setup_binlog.cpp b/maxscale-system-test/setup_binlog.cpp index f0858b316..d03cc3384 100644 --- a/maxscale-system-test/setup_binlog.cpp +++ b/maxscale-system-test/setup_binlog.cpp @@ -38,32 +38,15 @@ int main(int argc, char *argv[]) { + TestConnections test(argc, argv); - TestConnections * Test = new TestConnections(argc, argv); - Test->set_timeout(3000); - int options_set = 3; - if (Test->smoke) - { - options_set = 1; - } + test.binlog_cmd_option = 1; + test.start_binlog(); + test_binlog(&test); - Test->repl->connect(); - execute_query(Test->repl->nodes[0], (char *) "DROP TABLE IF EXISTS t1;"); - Test->repl->close_connections(); - sleep(5); + test.check_log_err("SET NAMES utf8mb4", false); + test.check_log_err("set autocommit=1", false); + test.check_log_err("select USER()", false); - for (int option = 0; option < options_set; option++) - { - Test->binlog_cmd_option = option; - Test->start_binlog(); - test_binlog(Test); - } - - Test->check_log_err("SET NAMES utf8mb4", false); - Test->check_log_err("set autocommit=1", false); - Test->check_log_err("select USER()", false); - - int rval = Test->global_result; - delete Test; - return rval; + return test.global_result; } diff --git a/maxscale-system-test/test_binlog_fnc.cpp b/maxscale-system-test/test_binlog_fnc.cpp index de54d6a74..b3414e1d7 100644 --- a/maxscale-system-test/test_binlog_fnc.cpp +++ b/maxscale-system-test/test_binlog_fnc.cpp @@ -29,7 +29,7 @@ int check_sha1(TestConnections* Test) local_result += execute_query(Test->repl->nodes[0], (char *) "FLUSH LOGS"); Test->tprintf("Logs flushed"); Test->set_timeout(100); - sleep(20); + Test->repl->sync_slaves(); Test->tprintf("ls after first FLUSH LOGS"); Test->tprintf("Maxscale"); Test->set_timeout(50); @@ -45,7 +45,7 @@ int check_sha1(TestConnections* Test) Test->tprintf("Logs flushed"); Test->set_timeout(50); - sleep(20); + Test->repl->sync_slaves(); Test->set_timeout(50); Test->tprintf("ls before FLUSH LOGS"); Test->tprintf("Maxscale"); @@ -86,7 +86,7 @@ int check_sha1(TestConnections* Test) } if (strcmp(s_maxscale, s) != 0) { - Test->tprintf("Binlog from master checksum is not eqiual to binlog checksum from Maxscale node"); + Test->tprintf("Binlog from master checksum is not equal to binlog checksum from Maxscale node"); local_result++; } } @@ -103,8 +103,9 @@ int start_transaction(TestConnections* Test) local_result += execute_query(Test->repl->nodes[0], (char *) "SET autocommit = 0"); Test->tprintf("INSERT data"); local_result += execute_query(Test->repl->nodes[0], (char *) "INSERT INTO t1 VALUES(111, 10)"); - Test->stop_timeout(); - sleep(20); + Test->set_timeout(120); + Test->repl->sync_slaves(); + return local_result; } @@ -123,8 +124,9 @@ void test_binlog(TestConnections* Test) create_t1(Test->repl->nodes[0]); Test->add_result(insert_into_t1(Test->repl->nodes[0], 4), "Data inserting to t1 failed"); Test->stop_timeout(); - Test->tprintf("Sleeping to let replication happen"); - sleep(60); + Test->tprintf("Waiting for replication to catch up"); + Test->set_timeout(120); + Test->repl->sync_slaves(); for (i = 0; i < Test->repl->N; i++) { @@ -150,8 +152,8 @@ void test_binlog(TestConnections* Test) Test->tprintf("INSERT INTO t1 VALUES(112, 10)"); Test->try_query(Test->repl->nodes[0], (char *) "INSERT INTO t1 VALUES(112, 10)"); Test->try_query(Test->repl->nodes[0], (char *) "COMMIT"); - Test->stop_timeout(); - sleep(20); + Test->set_timeout(120); + Test->repl->sync_slaves(); Test->set_timeout(20); Test->tprintf("SELECT * FROM t1 WHERE fl=10, checking inserted values"); @@ -217,9 +219,8 @@ void test_binlog(TestConnections* Test) Test->tprintf("START SLAVE against Maxscale binlog"); Test->try_query(binlog, (char *) "START SLAVE"); - Test->tprintf("Sleeping to let replication happen"); - Test->stop_timeout(); - sleep(30); + Test->set_timeout(120); + Test->repl->sync_slaves(); for (i = 0; i < Test->repl->N; i++) {