Refactor and fix slave_failover

The test seems to fail when executed outside of a debugger. A delay
between creating the connections and checking the connection count appears
to fix the problem.

Refactored the test to use stack allocated objects and favored assertion
style functions over conditional clauses with failing assertions inside
them.
This commit is contained in:
Markus Mäkelä
2017-06-02 18:48:09 +03:00
parent 9c5114b593
commit 3584001281
3 changed files with 31 additions and 52 deletions

View File

@ -17,6 +17,7 @@ max_slave_connections=1
servers=server1,server2,server3,server4 servers=server1,server2,server3,server4
user=maxskysql user=maxskysql
passwd=skysql passwd=skysql
router_options=disable_sescmd_history=false
[Read Connection Router Slave] [Read Connection Router Slave]
type=service type=service

View File

@ -461,14 +461,14 @@ int get_conn_num(MYSQL *conn, char * ip, char *hostname, char * db)
MYSQL_RES *res; MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
unsigned long long int num_fields; unsigned long long int num_fields;
//unsigned long long int row_i=0;
unsigned long long int rows; unsigned long long int rows;
unsigned long long int i; unsigned long long int i;
unsigned int conn_num = 0; unsigned int conn_num = 0;
char * hostname_internal; const char * hostname_internal;
if (strcmp(ip, "127.0.0.1") == 0) if (strcmp(ip, "127.0.0.1") == 0)
{ {
hostname_internal = (char*) "localhost"; hostname_internal = "localhost";
} }
else else
{ {
@ -516,9 +516,9 @@ int get_conn_num(MYSQL *conn, char * ip, char *hostname, char * db)
} }
if (strcmp(ip, "127.0.0.1") == 0) if (strcmp(ip, "127.0.0.1") == 0)
{ {
// one extra connection i svisible in the processlist // one extra connection is visible in the process list
// output in case of local test // output in case of local test
// (when maxscale is on the same machine as backends) // (when MaxScale is on the same machine as backends)
conn_num--; conn_num--;
} }
return conn_num; return conn_num;

View File

@ -16,59 +16,37 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
TestConnections * Test = new TestConnections(argc, argv); TestConnections test(argc, argv);
Test->set_timeout(20); printf("Connecting to RWSplit");
test.set_timeout(60);
test.add_result(test.connect_rwsplit(), "Error connection to RWSplit! Exiting");
sleep(5);
test.tprintf("Checking current slave");
int res = 0; int res = 0;
int old_slave = test.find_connected_slave(&res);
test.add_result(res, "no current slave");
unsigned int current_slave; test.tprintf("Setup firewall to block mysql on old slave (oldslave is node %d)", old_slave);
unsigned int old_slave;
printf("Connecting to RWSplit %s\n", Test->maxscale_IP); test.add_result((old_slave < 0) || (old_slave >= test.repl->N), "Active slave is not found");
if (Test->connect_rwsplit() != 0) test.repl->block_node(old_slave);
{
Test->add_result(1, "Error connection to RWSplit! Exiting\n");
}
else
{
Test->tprintf("Checking current slave\n"); test.tprintf("Waiting for MaxScale to find a new slave");
old_slave = Test->find_connected_slave( &res); test.stop_timeout();
sleep(10);
Test->add_result(res, "no current slave\n"); test.set_timeout(20);
int current_slave = test.find_connected_slave(&res);
test.add_result((current_slave == old_slave) || (current_slave < 0), "No failover happened");
Test->tprintf("Setup firewall to block mysql on old slave (oldslave is node %d)\n", old_slave); test.tprintf("Unblock old node");
if ((old_slave < 0) || (old_slave >= Test->repl->N)) test.repl->unblock_node(old_slave);
{ test.close_rwsplit();
Test->add_result(1, "Active slave is not found\n");
}
else
{
Test->repl->block_node(old_slave);
Test->tprintf("Sleeping 60 seconds to let MaxScale to find new slave\n"); test.check_maxscale_alive();
Test->stop_timeout(); test.stop_timeout();
sleep(60); test.repl->fix_replication();
Test->set_timeout(20);
current_slave = Test->find_connected_slave(&res); return test.global_result;
if ((current_slave == old_slave) || (current_slave < 0))
{
Test->add_result(1, "No failover happened\n");
}
Test->tprintf("Setup firewall back to allow mysql\n");
Test->repl->unblock_node(old_slave);
Test->close_rwsplit();
Test->check_maxscale_alive();
Test->set_timeout(20);
}
Test->set_timeout(200);
Test->repl->start_replication();
}
int rval = Test->global_result;
delete Test;
return rval;
} }