diff --git a/test/tap/tests/test_unshun_algorithm-t.cpp b/test/tap/tests/test_unshun_algorithm-t.cpp index 4a5714eaaf..78c28107bd 100644 --- a/test/tap/tests/test_unshun_algorithm-t.cpp +++ b/test/tap/tests/test_unshun_algorithm-t.cpp @@ -59,12 +59,12 @@ #include #include -#include #include #include +#include +#include #include "mysql.h" -#include "mysqld_error.h" #include "proxysql_utils.h" #include "tap.h" @@ -74,8 +74,11 @@ const uint32_t SHUN_RECOVERY_TIME = 1; const uint32_t VALID_RANGE = 1; const uint32_t SERVERS_COUNT = 10; +const uint32_t SYNC_TIMEOUT = 10; +using std::pair; using std::string; +using std::vector; int shunn_server(MYSQL* proxysql_admin, uint32_t i, uint32_t j) { std::string t_simulator_error_query { "PROXYSQL_SIMULATOR mysql_error %d 127.0.0.1:330%d 1234" }; @@ -426,8 +429,43 @@ int main(int argc, char** argv) { } // Disable Monitor for the following tests - MYSQL_QUERY(proxysql_admin, "SET mysql-monitor_enabled=0"); - MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); + MYSQL_QUERY_T(proxysql_admin, "SET mysql-monitor_enabled=0"); + MYSQL_QUERY_T(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); + + // We need to wait for synchronization in case 'admin-cluster_mysql_servers_sync_algorithm=1' to prevent + // circular fetches. If config is set to '2' we DO NOT wait, as circular fetches shouldn't be possible, + // this way a misbehavior **could** be detected by the test. We do not enforce failure either. + { + const char sync_algo_query[] { + "SELECT variable_value FROM global_variables" + " WHERE variable_name='admin-cluster_mysql_servers_sync_algorithm'", + }; + ext_val_t servers_sync_algo { mysql_query_ext_val(proxysql_admin, sync_algo_query, 1) }; + if (servers_sync_algo.err != EXIT_SUCCESS) { + const string err { get_ext_val_err(proxysql_admin, servers_sync_algo) }; + diag("Failed getting variable query:`%s`, err:`%s`", sync_algo_query, err.c_str()); + goto cleanup; + } + + // NOTE: '3' is a configuration thought for replicas, this test assumes it's connecting to a + // primary, so the same protection should be applied. + if (servers_sync_algo.val == 1 || servers_sync_algo.val == 3) { + const pair> core_nodes { fetch_cluster_nodes(proxysql_admin) }; + if (core_nodes.first) { + diag("Cluster node fetching failed with mysql_errno=%d", core_nodes.first); + goto cleanup; + } + + const char sync_query[] { + "SELECT CASE WHEN " + "(SELECT variable_value FROM runtime_global_variables WHERE" + " variable_name='mysql-monitor_enabled')='false'" + " THEN 1 ELSE 0 END" + }; + int check_res = check_nodes_sync(cl, core_nodes.second, sync_query, SYNC_TIMEOUT); + if (check_res != EXIT_SUCCESS) { goto cleanup; } + } + } { int simulator_err = test_proxysql_simulator_error(proxysql_admin);