MXS-1743: Expand test case to cover load balancing
The test case now verifies that the servers are actually load balanced correctly. This test reveals a problem in the readconnroute; the master is always preferred over slaves if one is available with router_options=master,slave.
This commit is contained in:
parent
cddcc6d7d5
commit
da4397a501
@ -4,12 +4,12 @@
|
||||
* https://jira.mariadb.org/browse/MXS-1743
|
||||
*/
|
||||
#include "testconnections.h"
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TestConnections test(argc, argv);
|
||||
|
||||
|
||||
test.tprintf("Testing with both master and slave up");
|
||||
test.maxscales->connect();
|
||||
test.try_query(test.maxscales->conn_master[0], "SELECT 1");
|
||||
@ -31,6 +31,44 @@ int main(int argc, char** argv)
|
||||
test.try_query(test.maxscales->conn_master[0], "SELECT 1");
|
||||
test.maxscales->disconnect();
|
||||
test.repl->unblock_node(1);
|
||||
sleep(5);
|
||||
|
||||
test.tprintf("Checking that both the master and slave are used");
|
||||
std::vector<MYSQL*> connections;
|
||||
|
||||
test.repl->connect();
|
||||
execute_query_silent(test.repl->nodes[0], "DROP USER IF EXISTS 'mxs1743'@'%'");
|
||||
test.try_query(test.repl->nodes[0], "%s", "CREATE USER 'mxs1743'@'%' IDENTIFIED BY 'mxs1743'");
|
||||
test.try_query(test.repl->nodes[0], "%s", "GRANT ALL ON *.* TO 'mxs1743'@'%'");
|
||||
test.repl->sync_slaves();
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
connections.push_back(open_conn(test.maxscales->readconn_master_port[0],
|
||||
test.maxscales->IP[0], "mxs1743",
|
||||
"mxs1743", false));
|
||||
}
|
||||
|
||||
// Give the connections a few seconds to establish
|
||||
sleep(5);
|
||||
|
||||
std::string query = "SELECT COUNT(*) AS connections FROM information_schema.processlist WHERE user = 'mxs1743'";
|
||||
char master_connections[1024];
|
||||
char slave_connections[1024];
|
||||
find_field(test.repl->nodes[0], query.c_str(), "connections", master_connections);
|
||||
find_field(test.repl->nodes[1], query.c_str(), "connections", slave_connections);
|
||||
|
||||
test.assert(strcmp(master_connections, slave_connections) == 0,
|
||||
"Master and slave shoud have the same amount of connections: %s != %s",
|
||||
master_connections, slave_connections);
|
||||
|
||||
for (auto a: connections)
|
||||
{
|
||||
mysql_close(a);
|
||||
}
|
||||
|
||||
execute_query_silent(test.repl->nodes[0], "DROP USER 'mxs1743'@'%'");
|
||||
test.repl->disconnect();
|
||||
|
||||
return test.global_result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user