MaxScale/maxscale-system-test/mxs1503_extra_slaves.cpp
Markus Mäkelä e3b11d866f
Use explicit types with get_row
Auto types aren't very neat as return values because they move the burden
of knowledge to the reader. Using an explicit, and somewhat
self-explanatory, type makes it easier to assess the code without knowing
the implementation of the type.
2018-04-13 08:48:21 +03:00

46 lines
1.2 KiB
C++

/**
* MXS-1503: Make sure no extra slaves are taken into use
*
* https://jira.mariadb.org/browse/MXS-1503
*/
#include "testconnections.h"
#include <vector>
#include <thread>
#include <iostream>
void query(MYSQL* conn, std::string q)
{
execute_query(conn, "%s", q.c_str());
mysql_close(conn);
}
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
std::vector<std::thread> connections;
test.maxscales->connect();
Row original_row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @@server_id");
for (int i = 0; i < 10; i++)
{
connections.emplace_back(query, test.maxscales->open_rwsplit_connection(), "SELECT SLEEP(10)");
sleep(1);
Row row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @@server_id");
test.assert(row == original_row, "Value of @@server_id should not change: %s", row.at(0).c_str());
}
for (auto& a: connections)
{
a.join();
Row row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @@server_id");
test.assert(row == original_row, "Value of @@server_id should not change: %s", row.at(0).c_str());
}
test.maxscales->disconnect();
return test.global_result;
}