diff --git a/maxscale-system-test/slave_failover.cpp b/maxscale-system-test/slave_failover.cpp index ae4ae00b0..cd31bbe78 100644 --- a/maxscale-system-test/slave_failover.cpp +++ b/maxscale-system-test/slave_failover.cpp @@ -18,36 +18,50 @@ int main(int argc, char* argv[]) { TestConnections test(argc, argv); - printf("Connecting to RWSplit"); + test.set_timeout(60); - test.add_result(test.maxscales->connect_rwsplit(0), "Error connection to RWSplit! Exiting"); - test.maxscales->wait_for_monitor(); + test.repl->connect(); + auto ids = test.repl->get_all_server_ids(); + test.repl->disconnect(); - test.tprintf("Checking current slave"); - int res = 0; - int old_slave = test.find_connected_slave(0, &res); - test.add_result(res, "no current slave"); + auto conn = test.maxscales->rwsplit(); + test.expect(conn.connect(), "Connection to rwsplit should work: %s", conn.error()); - test.tprintf("Setup firewall to block mysql on old slave (oldslave is node %d)", old_slave); + auto first_slave = conn.field("SELECT @@server_id"); + conn.disconnect(); - test.add_result((old_slave < 0) || (old_slave >= test.repl->N), "Active slave is not found"); - test.repl->block_node(old_slave); + test.expect(!first_slave.empty(), "Result should not be empty"); + int slave = std::stoi(first_slave); + test.expect(slave != ids[0], "The result should not be from the master"); - test.tprintf("Waiting for MaxScale to find a new slave"); - test.stop_timeout(); - test.maxscales->wait_for_monitor(); + test.set_timeout(60); + for (int i = 1; i < test.repl->N; i++) + { + if (ids[i] == slave) + { + test.repl->block_node(i); + test.maxscales->wait_for_monitor(); + break; + } + } - test.set_timeout(20); - int current_slave = test.find_connected_slave(0, &res); - test.add_result((current_slave == old_slave) || (current_slave < 0), "No failover happened"); + test.set_timeout(60); + test.expect(conn.connect(), "Connection to rwsplit should work: %s", conn.error()); + auto second_slave = conn.field("SELECT @@server_id"); - test.tprintf("Unblock old node"); - test.repl->unblock_node(old_slave); - test.maxscales->close_rwsplit(0); + test.expect(!second_slave.empty(), "Second result should not be empty"); + test.expect(first_slave != second_slave, "The slave should change"); + slave = std::stoi(second_slave); + test.expect(slave != ids[0], "The result should not be from the master"); - test.check_maxscale_alive(0); - test.stop_timeout(); - test.repl->fix_replication(); + for (int i = 1; i < test.repl->N; i++) + { + if (ids[i] == slave) + { + test.repl->unblock_node(i); + break; + } + } return test.global_result; }