Rewrite slave_failover
The test now uses the @@server_id server variable to detect which server is used. This is a lot less error prone than comparing hostnames is.
This commit is contained in:
@ -18,36 +18,50 @@
|
|||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
TestConnections test(argc, argv);
|
TestConnections test(argc, argv);
|
||||||
printf("Connecting to RWSplit");
|
|
||||||
test.set_timeout(60);
|
test.set_timeout(60);
|
||||||
test.add_result(test.maxscales->connect_rwsplit(0), "Error connection to RWSplit! Exiting");
|
test.repl->connect();
|
||||||
|
auto ids = test.repl->get_all_server_ids();
|
||||||
|
test.repl->disconnect();
|
||||||
|
|
||||||
|
auto conn = test.maxscales->rwsplit();
|
||||||
|
test.expect(conn.connect(), "Connection to rwsplit should work: %s", conn.error());
|
||||||
|
|
||||||
|
auto first_slave = conn.field("SELECT @@server_id");
|
||||||
|
conn.disconnect();
|
||||||
|
|
||||||
|
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.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();
|
test.maxscales->wait_for_monitor();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test.tprintf("Checking current slave");
|
test.set_timeout(60);
|
||||||
int res = 0;
|
test.expect(conn.connect(), "Connection to rwsplit should work: %s", conn.error());
|
||||||
int old_slave = test.find_connected_slave(0, &res);
|
auto second_slave = conn.field("SELECT @@server_id");
|
||||||
test.add_result(res, "no current slave");
|
|
||||||
|
|
||||||
test.tprintf("Setup firewall to block mysql on old slave (oldslave is node %d)", old_slave);
|
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.add_result((old_slave < 0) || (old_slave >= test.repl->N), "Active slave is not found");
|
for (int i = 1; i < test.repl->N; i++)
|
||||||
test.repl->block_node(old_slave);
|
{
|
||||||
|
if (ids[i] == slave)
|
||||||
test.tprintf("Waiting for MaxScale to find a new slave");
|
{
|
||||||
test.stop_timeout();
|
test.repl->unblock_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.tprintf("Unblock old node");
|
|
||||||
test.repl->unblock_node(old_slave);
|
|
||||||
test.maxscales->close_rwsplit(0);
|
|
||||||
|
|
||||||
test.check_maxscale_alive(0);
|
|
||||||
test.stop_timeout();
|
|
||||||
test.repl->fix_replication();
|
|
||||||
|
|
||||||
return test.global_result;
|
return test.global_result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user