MXS-1506: Add cluster failure test

The test exercises the retrying code by failing both nodes.
This commit is contained in:
Markus Mäkelä
2018-04-11 11:43:17 +03:00
parent 3aa62b0116
commit 385a221194
2 changed files with 65 additions and 0 deletions

View File

@ -606,6 +606,10 @@ add_test_executable(mxs1503_extra_slaves.cpp mxs1503_extra_slaves mxs1503_extra_
# https://jira.mariadb.org/browse/MXS-1506
add_test_executable(mxs1506_delayed_retry.cpp mxs1506_delayed_retry mxs1506_delayed_retry LABELS readwritesplit REPL_BACKEND)
# MXS-1506: Delayed retry without master
# https://jira.mariadb.org/browse/MXS-1506
add_test_executable(mxs1506_no_master.cpp mxs1506_no_master mxs1506_delayed_retry LABELS readwritesplit REPL_BACKEND)
# MXS-1509: Show correct server state for multisource replication
# https://jira.mariadb.org/browse/MXS-1509
add_test_executable(mxs1509.cpp mxs1509 mxs1509 LABELS mysqlmon REPL_BACKEND)

View File

@ -0,0 +1,61 @@
/**
* MXS-1506: Delayed query retry without master
*
* https://jira.mariadb.org/browse/MXS-1506
*/
#include "testconnections.h"
#include <string>
#include <functional>
#include <thread>
#include <iostream>
#include <vector>
using namespace std;
bool query(TestConnections& test)
{
test.maxscales->connect();
execute_query_silent(test.maxscales->conn_rwsplit[0], "SET @a = 1") == 0;
sleep(5);
auto row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @a");
test.maxscales->disconnect();
return row[0] == "1";
}
void block(TestConnections& test, std::vector<int> nodes)
{
for (auto a : nodes)
{
test.repl->block_node(a);
}
sleep(10);
for (auto a : nodes)
{
test.repl->unblock_node(a);
}
}
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
thread thr;
cout << "Blocking the master and executing a SELECT" << endl;
thr = thread(block, std::ref(test), vector<int>({0}));
test.assert(query(test), "Select without master should work");
thr.join();
cout << "Blocking the slave and executing a SELECT" << endl;
thr = thread(block, std::ref(test), vector<int>({1}));
test.assert(query(test), "Select without slave should work");
thr.join();
cout << "Blocking both servers and executing a SELECT" << endl;
thr = thread(block, std::ref(test), vector<int>({0, 1}));
test.assert(query(test), "Select with no servers should work");
thr.join();
return test.global_result;
}