MXS-1889 Improve test program
Verify that once there are slaves, we are connected to a slave as expected.
This commit is contained in:
@ -5,32 +5,81 @@
|
||||
*/
|
||||
|
||||
#include "testconnections.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
string get_server_id(TestConnections& test, MYSQL* pMysql)
|
||||
{
|
||||
string id;
|
||||
|
||||
int rv = mysql_query(pMysql, "SELECT @@server_id");
|
||||
test.add_result(rv, "Could not execute query.");
|
||||
|
||||
if (rv == 0)
|
||||
{
|
||||
MYSQL_RES* pResult = mysql_store_result(pMysql);
|
||||
test.assert(pResult, "Could not store result.");
|
||||
|
||||
if (pResult)
|
||||
{
|
||||
unsigned int n = mysql_field_count(pMysql);
|
||||
test.assert(n == 1, "Unexpected number of fields.");
|
||||
|
||||
MYSQL_ROW pzRow = mysql_fetch_row(pResult);
|
||||
test.assert(pzRow, "Returned row was NULL.");
|
||||
|
||||
if (pzRow)
|
||||
{
|
||||
id = pzRow[0];
|
||||
}
|
||||
|
||||
mysql_free_result(pResult);
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TestConnections test(argc, argv);
|
||||
|
||||
// Give some time for things to stabilize.
|
||||
sleep(2);
|
||||
|
||||
// Take down all slaves.
|
||||
test.tprintf("Taking down all slaves.");
|
||||
test.repl->stop_node(1);
|
||||
test.repl->stop_node(2);
|
||||
test.repl->stop_node(3);
|
||||
|
||||
// Give the monitor some time to detect it
|
||||
test.tprintf("Giving monitor time to detect the situation...");
|
||||
sleep(5);
|
||||
|
||||
test.maxscales->connect();
|
||||
|
||||
// Should succeed.
|
||||
test.try_query(test.maxscales->conn_slave[0], "SELECT 1");
|
||||
// All slaves down, so we expect a connection to the master.
|
||||
string master_id = get_server_id(test, test.maxscales->conn_slave[0]);
|
||||
test.tprintf("Master id: %s", master_id.c_str());
|
||||
|
||||
int rv = test.global_result;
|
||||
test.maxscales->disconnect();
|
||||
|
||||
test.tprintf("Starting all slaves.");
|
||||
test.repl->start_node(3);
|
||||
test.repl->start_node(2);
|
||||
test.repl->start_node(1);
|
||||
|
||||
return rv;
|
||||
test.tprintf("Giving monitor time to detect the situation...");
|
||||
sleep(5);
|
||||
|
||||
test.maxscales->connect();
|
||||
|
||||
string slave_id = get_server_id(test, test.maxscales->conn_slave[0]);
|
||||
test.tprintf("Server id: %s", slave_id.c_str());
|
||||
test.assert(slave_id != master_id, "Expected something else but %s", master_id.c_str());
|
||||
|
||||
return test.global_result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user