From 9b00eb33a592ef191d97c0bb70236cb13127c2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Thu, 11 Jan 2024 11:22:51 +0100 Subject: [PATCH] Make 'test_cluster_sync_mysql_servers' exit gracefully in clusterless env Current GitHub actions testing environment lacks of a ProxySQL cluster. This change allows the test to gracefully exit when the env conditions for it are not met. --- .../test_cluster_sync_mysql_servers-t.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/tap/tests/test_cluster_sync_mysql_servers-t.cpp b/test/tap/tests/test_cluster_sync_mysql_servers-t.cpp index 8d258710fe..a1338a4a8d 100644 --- a/test/tap/tests/test_cluster_sync_mysql_servers-t.cpp +++ b/test/tap/tests/test_cluster_sync_mysql_servers-t.cpp @@ -53,6 +53,8 @@ #include "command_line.h" #include "utils.h" +using std::string; + #define MYSQL_QUERY__(mysql, query) \ do { \ if (mysql_query(mysql, query)) { \ @@ -863,6 +865,28 @@ int main(int, char**) { std::vector core_nodes { extract_mysql_rows(my_res) }; mysql_free_result(my_res); + // 2.1 If core nodes are not reachable, assume no cluster is running; make test gracefully exit + if (core_nodes.size()) { + const string host { core_nodes[0][0] }; + const int port = std::stol(core_nodes[0][1]); + MYSQL* c_node_admin = mysql_init(NULL); + + if (!mysql_real_connect(c_node_admin, host.c_str(), cl.admin_username, cl.admin_password, NULL, port, NULL, 0)) { + int myerrno = mysql_errno(c_node_admin); + + if (myerrno == 2002) { + diag("Unable to connect to cluster Core nodes; required environment not met, gracefully exiting..."); + plan(0); + return exit_status(); + } else { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); + return EXIT_FAILURE; + } + } + + mysql_close(c_node_admin); + } + // 3. Wait for all Core nodes to sync (confirm primary out of core nodes) std::string check_no_primary_query {}; string_format(