Skip to content

Commit

Permalink
Prevent circular fetches due for 'test_unshun_algorithm-t'
Browse files Browse the repository at this point in the history
Test is now aware of 'cluster_mysql_servers_sync_algorithm'. In case of
'runtime_mysql_servers' propagation, the test disables monitoring since
it creates servers in hostgroups with active monitoring, if config
doesn't allows 'runtime' propagation, the test assumes everything will
just work. This should be a common pattern for tests creating fake
servers.
  • Loading branch information
JavierJF committed Jul 17, 2024
1 parent dcc1648 commit 77864bf
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions test/tap/tests/test_unshun_algorithm-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@

#include <cstring>
#include <unistd.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <utility>
#include <vector>

#include "mysql.h"
#include "mysqld_error.h"

#include "proxysql_utils.h"
#include "tap.h"
Expand All @@ -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" };
Expand Down Expand Up @@ -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<int32_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<int,vector<srv_addr_t>> 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);
Expand Down

0 comments on commit 77864bf

Please sign in to comment.