MXS-1678: Add test case

Added test case that checks that relay master status is not lost when IO
thread is stopped.
This commit is contained in:
Markus Mäkelä 2018-02-21 10:43:12 +02:00
parent 1ecd791887
commit 8e31b30d19
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 90 additions and 0 deletions

View File

@ -530,6 +530,10 @@ add_test_executable(mxs1543.cpp mxs1543 avro LABELS REPL_BACKEND)
# https://jira.mariadb.org/browse/MXS-1585
add_test_executable(mxs1585.cpp mxs1585 mxs1585 LABELS REPL_BACKEND)
# MXS-1678: Stopping IO thread on relay master causes it to be promoted as master
# https://jira.mariadb.org/browse/MXS-1678
add_test_executable(mxs1678_relay_master.cpp mxs1678_relay_master replication LABELS REPL_BACKEND)
# 'namedserverfilter' test
add_test_executable(namedserverfilter.cpp namedserverfilter namedserverfilter LABELS namedserverfilter LIGHT REPL_BACKEND)

View File

@ -0,0 +1,86 @@
/**
* MXS-1678: Stopping IO thread on relay master causes it to be promoted as master
*
* https://jira.mariadb.org/browse/MXS-1678
*/
#include "testconnections.h"
#include <set>
#include <string>
typedef std::set<std::string> StringSet;
// Note: This is backported from 2.2 and can be replaced with MaxScales::get_server_status once merged
StringSet state(TestConnections& test, const char* name)
{
StringSet rval;
char* res = test.ssh_maxscale_output(true, "maxadmin list servers|grep \'%s\'", name);
char* pipe = strrchr(res, '|');
if (res && pipe)
{
pipe++;
char* tok = strtok(pipe, ",");
while (tok)
{
char* p = tok;
char *end = strchr(tok, '\n');
if (!end)
{
end = strchr(tok, '\0');
}
// Trim leading whitespace
while (p < end && isspace(*p))
{
p++;
}
// Trim trailing whitespace
while (end > tok && isspace(*end))
{
*end-- = '\0';
}
rval.insert(p);
tok = strtok(NULL, ",\n");
}
}
free(res);
return rval;
}
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
test.repl->connect();
execute_query(test.repl->nodes[3], "STOP SLAVE");
execute_query(test.repl->nodes[3], "CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d",
test.repl->IP_private[2], test.repl->port[2]);
execute_query(test.repl->nodes[3], "START SLAVE");
StringSet master = {"Master", "Running"};
StringSet slave = {"Slave", "Running"};
StringSet relay_master = {"Relay Master", "Slave", "Running"};
test.tprintf("Checking before stopping IO thread");
test.add_result(state(test, "server1") != master, "server1 is not a master");
test.add_result(state(test, "server2") != slave, "server2 is not a slave");
test.add_result(state(test, "server3") != relay_master, "server3 is not a relay master");
test.add_result(state(test, "server4") != slave, "server4 is not a slave");
execute_query(test.repl->nodes[2], "STOP SLAVE IO_THREAD");
sleep(10);
test.tprintf("Checking after stopping IO thread");
test.add_result(state(test, "server1") != master, "server1 is not a master");
test.add_result(state(test, "server2") != slave, "server2 is not a slave");
test.add_result(state(test, "server3") != relay_master, "server3 is not a relay master");
test.add_result(state(test, "server4") != slave, "server4 is not a slave");
test.repl->fix_replication();
return test.global_result;
}