MXS-1509: Initial implementation of test case

Added some code to detect server states in a consistent manner and created
the test. The multi-source replication appeared to cause problems for the
test system which needs to be resolved.

Added --force flags to most direct `mysql` calls to prevent errors from
stopping the processing of remaining commands.
This commit is contained in:
Markus Mäkelä
2017-11-23 12:58:21 +02:00
parent d5d41349ae
commit 016b0f69f7
5 changed files with 189 additions and 12 deletions

View File

@ -0,0 +1,95 @@
/**
* MXS-1509: Show correct server state for multisource replication
*
* https://jira.mariadb.org/browse/MXS-1509
*/
#include "testconnections.h"
#include <sstream>
void change_master(TestConnections& test, int slave, int master, const char* name = NULL)
{
std::string source;
if (name)
{
source = "'";
source += name;
source += "'";
}
execute_query(test.repl->nodes[slave], "STOP ALL SLAVES;CHANGE MASTER %s TO master_host='%s', master_port=3306, "
"master_user='%s', master_password='%s', master_use_gtid=slave_pos;START ALL SLAVES",
source.c_str(), test.repl->IP[master], test.repl->user_name, test.repl->password, source.c_str());
}
const char* dump_status(const StringSet& current, const StringSet& expected)
{
std::stringstream ss;
ss << "Current status: (";
for (const auto& a: current)
{
ss << a << ",";
}
ss << ") Expected status: (";
for (const auto& a: expected)
{
ss << a << ",";
}
ss << ")";
static std::string res = ss.str();
return res.c_str();
}
void check_status(TestConnections& test, const StringSet& expected_master, const StringSet& expected_slave)
{
sleep(2);
StringSet master = test.get_server_status("server1");
StringSet slave = test.get_server_status("server2");
test.add_result(master != expected_master, "Master status is not what was expected: %s",
dump_status(master, expected_master));
test.add_result(slave != expected_slave, "Slave status is not what was expected: %s",
dump_status(slave, expected_slave));
}
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
// Stop replication on nodes three and four
test.repl->connect();
execute_query(test.repl->nodes[2], "STOP ALL SLAVES; RESET SLAVE ALL;");
execute_query(test.repl->nodes[3], "STOP ALL SLAVES; RESET SLAVE ALL;");
// Point the master to an external server
change_master(test, 1, 0);
change_master(test, 0, 2);
check_status(test, {"Master", "Running"}, {"Slave", "Running"});
// Resetting the slave on master should have no effect
execute_query(test.repl->nodes[0], "STOP ALL SLAVES; RESET SLAVE ALL;");
check_status(test, {"Master", "Running"}, {"Slave", "Running"});
// Configure multi-source replication, check that master status is as expected
change_master(test, 0, 2, "extra-slave");
change_master(test, 1, 2, "extra-slave");
check_status(test, {"Master", "Running"}, {"Slave", "Running", "Slave of External Server"});
// Stopping multi-source replication on slave should remove the Slave of External Server status
execute_query(test.repl->nodes[1], "STOP SLAVE 'extra-slave'; RESET SLAVE 'extra-slave';");
check_status(test, {"Master", "Running"}, {"Slave", "Running"});
// Doing the same on the master should have no effect
execute_query(test.repl->nodes[0], "STOP ALL SLAVES; RESET SLAVE ALL;");
check_status(test, {"Master", "Running"}, {"Slave", "Running"});
// Cleanup
test.repl->execute_query_all_nodes( "STOP ALL SLAVES; RESET SLAVE ALL;");
test.repl->fix_replication();
return test.global_result;
}