MXS-2970: Add test case

Test case reproduces the problem and verifies that it is fixed.
This commit is contained in:
Markus Mäkelä
2020-04-22 10:07:39 +03:00
parent 25b8eeb415
commit 4480debefd
4 changed files with 87 additions and 0 deletions

View File

@ -945,6 +945,9 @@ add_test_executable(mxs2939_sescmd_reconnect.cpp mxs2939_sescmd_reconnect mxs293
# MXS-2919: Slaves with broken replication should not be used
add_test_executable(mxs2919_broken_slaves.cpp mxs2919_broken_slaves mxs2919_broken_slaves LABELS REPL_BACKEND readwritesplit)
# MXS-2972: Caching of shards must take servers into notice
add_test_executable(mxs2972_shard_caching.cc mxs2972_shard_caching mxs2972_shard_caching LABELS REPL_BACKEND schemarouter)
############################################
# END: Normal tests #
############################################

View File

@ -0,0 +1,34 @@
[maxscale]
threads=###threads###
###server###
[MariaDB-Monitor]
type=monitor
module=mysqlmon
servers=###server_line###
user=maxskysql
password=skysql
monitor_interval=1000
[Matcher]
type=filter
module=namedserverfilter
match01=DELETE
target01=server1
[Schemarouter]
type=service
router=schemarouter
servers=###server_line###
user=maxskysql
password=skysql
ignore_databases_regex=.*
preferred_server=server1
filters=Matcher
[Schemarouter-Listener]
type=listener
service=Schemarouter
protocol=MariaDBClient
port=4006

View File

@ -353,6 +353,11 @@ public:
m_pw = pw;
}
void set_database(const std::string& db)
{
m_db = db;
}
uint32_t thread_id() const
{
return mysql_thread_id(m_conn);

View File

@ -0,0 +1,45 @@
#include <testconnections.h>
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
test.repl->connect();
test.try_query(test.repl->nodes[0], "CREATE DATABASE db1");
test.try_query(test.repl->nodes[0], "CREATE OR REPLACE TABLE test.t1(id INT)");
test.repl->disconnect();
auto conn = test.maxscales->rwsplit();
conn.set_database("db1");
test.tprintf("Block server1 and perform a simple SELECT");
test.repl->block_node(0);
test.maxscales->wait_for_monitor();
test.expect(conn.connect(), "Connection should work: %s", conn.error());
auto db = conn.field("SELECT DATABASE()");
test.expect(db == "db1", "Database should be `db1`: %s", db.c_str());
test.expect(conn.query("SELECT 1"), "Query should work: %s", conn.error());
conn.disconnect();
test.repl->unblock_node(0);
test.maxscales->wait_for_monitor();
test.tprintf("Unblock server1 and perform a DELETE that is forced to server1");
test.expect(conn.connect(), "Connection should work: %s", conn.error());
db = conn.field("SELECT DATABASE()");
test.expect(db == "db1", "Database should be `db1`: %s", db.c_str());
test.expect(conn.query("DELETE t FROM test.t1 AS t"), "Query should work: %s", conn.error());
conn.disconnect();
test.repl->connect();
test.try_query(test.repl->nodes[0], "DROP DATABASE db1");
test.try_query(test.repl->nodes[0], "DROP TABLE test.t1");
test.repl->disconnect();
return test.global_result;
}