MXS-1506: Add test case

Added a test case that performs basic testing of the functionality.
This commit is contained in:
Markus Mäkelä
2018-04-09 19:31:48 +03:00
parent 948ff9b5f1
commit 93f589ffa2
4 changed files with 179 additions and 1 deletions

View File

@ -599,6 +599,10 @@ add_test_executable(mxs1503_master_reconnection.cpp mxs1503_master_reconnection
# Master reconnection with session commands
add_test_executable(mxs1503_queued_sescmd.cpp mxs1503_queued_sescmd mxs1503_master_reconnection LABELS readwritesplit REPL_BACKEND)
# MXS-1506: Delayed query retry
# 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-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,65 @@
[maxscale]
threads=###threads###
log_info=1
[MySQL Monitor]
type=monitor
module=mysqlmon
###repl51###
servers=server1,server2,server3,server4
user=maxskysql
passwd=skysql
monitor_interval=1000
backend_read_timeout=1
backend_connect_timeout=1
[RW Split Router]
type=service
router=readwritesplit
servers=server1,server2,server3,server4
user=maxskysql
passwd=skysql
master_failure_mode=fail_on_write
master_reconnection=true
delayed_retry=true
delayed_retry_timeout=15
[RW Split Listener]
type=listener
service=RW Split Router
protocol=MySQLClient
port=4006
[CLI]
type=service
router=cli
[CLI Listener]
type=listener
service=CLI
protocol=maxscaled
socket=default
[server1]
type=server
address=###node_server_IP_1###
port=###node_server_port_1###
protocol=MySQLBackend
[server2]
type=server
address=###node_server_IP_2###
port=###node_server_port_2###
protocol=MySQLBackend
[server3]
type=server
address=###node_server_IP_3###
port=###node_server_port_3###
protocol=MySQLBackend
[server4]
type=server
address=###node_server_IP_4###
port=###node_server_port_4###
protocol=MySQLBackend

View File

@ -214,7 +214,7 @@ int execute_query_check_one(MYSQL* conn, const char* sql, const char* expected)
}
else
{
printf("First field is '%s, but expected %s'\n", row[0], expected);
printf("First field is '%s', but expected '%s'\n", row[0], expected);
}
}
else

View File

@ -0,0 +1,109 @@
/**
* MXS-1506: Delayed query retry
*
* https://jira.mariadb.org/browse/MXS-1506
*/
#include "testconnections.h"
#include <functional>
#include <thread>
#include <iostream>
#include <vector>
using namespace std;
struct TestCase
{
string description;
function<void ()> pre; // Called before master goes down
function<void ()> main; // Called after master goes down
function<void ()> check; // Called after connection is closed
};
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
auto query = [&test](string q)
{
return execute_query_silent(test.maxscales->conn_rwsplit[0], q.c_str()) == 0;
};
auto check = [&test](string q, string res)
{
test.repl->sync_slaves();
test.maxscales->connect();
auto rc = execute_query_check_one(test.maxscales->conn_rwsplit[0], q.c_str(), res.c_str()) == 0;
test.maxscales->disconnect();
test.assert(rc, "Query '%s' did not produce result of '%s'", q.c_str(), res.c_str());
};
auto ok = [&test, &query](string q)
{
test.assert(query(q), "Query '%' should work: %s", q.c_str(), mysql_error(test.maxscales->conn_rwsplit[0]));
};
auto err = [&test, &query](string q)
{
test.assert(!query(q), "Query should fail: %s", q.c_str());
};
auto block_master = [&test]()
{
test.repl->block_node(0);
sleep(10);
test.repl->unblock_node(0);
};
vector<TestCase> tests(
{
{
"Test autocommit insert with master disconnection",
bind(ok, "SELECT 1"),
bind(ok, "INSERT INTO test.t1 VALUES (1)"),
bind(check, "SELECT COUNT(*) FROM test.t1 WHERE id = 1", "1")
},
{
"Test user variables in insert with master disconnection",
bind(ok, "SET @a = 2"),
bind(ok, "INSERT INTO test.t1 VALUES (@a)"),
bind(check, "SELECT COUNT(*) FROM test.t1 WHERE id = 2", "1")
},
{
"Check that writes in transactions aren't retried",
bind(ok, "START TRANSACTION"),
bind(err, "INSERT INTO test.t1 VALUES (3)"),
bind(check, "SELECT COUNT(*) FROM test.t1 WHERE id = 3", "0")
},
{
"Check that writes without autocommit aren't retried",
bind(ok, "SET autocommit=0"),
bind(err, "INSERT INTO test.t1 VALUES (4)"),
bind(check, "SELECT COUNT(*) FROM test.t1 WHERE id = 4", "0")
}
});
cout << "Create table for testing" << endl;
test.maxscales->connect();
ok("DROP TABLE IF EXISTS test.t1");
ok("CREATE TABLE test.t1 (id INT)");
test.maxscales->disconnect();
for (auto a : tests)
{
cout << a.description << endl;
test.maxscales->connect();
a.pre();
thread thr(block_master);
sleep(5);
a.main();
test.maxscales->disconnect();
thr.join();
a.check();
}
test.maxscales->connect();
query("DROP TABLE test.t1");
test.maxscales->disconnect();
return test.global_result;
}