From ef25eceb78625cfe4a8ed96a173c331a56b1ea26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 7 May 2019 12:42:05 +0300 Subject: [PATCH] Test lazy_connect The test makes sure the various corner cases are covered by the test suite. --- maxscale-system-test/CMakeLists.txt | 3 ++ ...maxscale.cnf.template.mxs2350_lazy_connect | 26 +++++++++++++ maxscale-system-test/mxs2350_lazy_connect.cpp | 39 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100755 maxscale-system-test/cnf/maxscale.cnf.template.mxs2350_lazy_connect create mode 100644 maxscale-system-test/mxs2350_lazy_connect.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index e7b58c110..6cb4aae97 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -961,6 +961,9 @@ add_test_executable(mxs2414_host_blocking.cpp mxs2414_host_blocking replication # PAM authentication add_test_executable(pam_authentication.cpp pam_authentication pam_authentication LABELS REPL_BACKEND) +# MXS-2350: On-demand connection creation +add_test_executable(mxs2350_lazy_connect.cpp mxs2350_lazy_connect mxs2350_lazy_connect LABELS REPL_BACKEND) + ############################################ # BEGIN: binlogrouter and avrorouter tests # ############################################ diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.mxs2350_lazy_connect b/maxscale-system-test/cnf/maxscale.cnf.template.mxs2350_lazy_connect new file mode 100755 index 000000000..69c00674a --- /dev/null +++ b/maxscale-system-test/cnf/maxscale.cnf.template.mxs2350_lazy_connect @@ -0,0 +1,26 @@ +[maxscale] +threads=###threads### + +###server### + +[MySQL-Monitor] +type=monitor +module=mysqlmon +servers=###server_line### +user=maxskysql +password=skysql +monitor_interval=1000 + +[RW-Split-Router] +type=service +router=readwritesplit +servers=###server_line### +user=maxskysql +password=skysql +lazy_connect=true + +[RW-Split-Listener] +type=listener +service=RW-Split-Router +protocol=MySQLClient +port=4006 diff --git a/maxscale-system-test/mxs2350_lazy_connect.cpp b/maxscale-system-test/mxs2350_lazy_connect.cpp new file mode 100644 index 000000000..0021f3e4a --- /dev/null +++ b/maxscale-system-test/mxs2350_lazy_connect.cpp @@ -0,0 +1,39 @@ +/** + * MXS-2350: On-demand connection creation + * https://jira.mariadb.org/browse/MXS-2350 + */ + +#include "testconnections.h" +#include + +int main(int argc, char* argv[]) +{ + TestConnections test(argc, argv); + Connection c = test.maxscales->rwsplit(); + + test.expect(c.connect(), "Connection should work"); + auto output = test.maxscales->ssh_output("maxctrl list servers --tsv|cut -f 4|sort|uniq").second; + mxb::trim(output); + test.expect(output == "0", "Servers should have no connections: %s", output.c_str()); + c.disconnect(); + + test.expect(c.connect(), "Connection should work"); + test.expect(c.query("SELECT 1"), "Read should work"); + c.disconnect(); + + test.expect(c.connect(), "Connection should work"); + test.expect(c.query("SELECT @@last_insert_id"), "Write should work"); + c.disconnect(); + + test.expect(c.connect(), "Connection should work"); + test.expect(c.query("SET @a = 1"), "Session command should work"); + c.disconnect(); + + test.expect(c.connect(), "Connection should work"); + test.expect(c.query("BEGIN"), "BEGIN should work"); + test.expect(c.query("SELECT 1"), "Read should work"); + test.expect(c.query("COMMIT"), "COMMIT command should work"); + c.disconnect(); + + return test.global_result; +}