Files
MaxScale/maxscale-system-test/slave_failover.cpp
Markus Mäkelä 195a016b7c 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.
2019-10-29 11:33:10 +02:00

68 lines
2.0 KiB
C++

/**
* @file slave_failover.cpp Check how Maxscale works in case of one slave failure, only one slave is
* configured
*
* - Connect to RWSplit
* - find which backend slave is used for connection
* - blocm mariadb on the slave with firewall
* - wait 60 seconds
* - check which slave is used for connection now, expecting any other slave
* - check warning in the error log about broken slave
* - unblock mariadb backend (restore slave firewall settings)
* - check if Maxscale still alive
*/
#include "testconnections.h"
int main(int argc, char* argv[])
{
TestConnections test(argc, argv);
test.set_timeout(60);
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();
break;
}
}
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.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");
for (int i = 1; i < test.repl->N; i++)
{
if (ids[i] == slave)
{
test.repl->unblock_node(i);
break;
}
}
return test.global_result;
}