Minor test fixes

Same fixes are in commit 1bc48ad in PR #3899
pull/3902/head
René Cannaò 4 years ago
parent 3afcc12b84
commit aeeaaba845

@ -146,7 +146,7 @@ build_tap_test: build_src
cd test/tap && OPTZ="${O0} -ggdb -DDEBUG" CC=${CC} CXX=${CXX} ${MAKE}
.PHONY: build_tap_test_debug
build_tap_test_debug: build_src
build_tap_test_debug: build_src_debug
cd test/tap && OPTZ="${O0} -ggdb -DDEBUG" CC=${CC} CXX=${CXX} ${MAKE} debug
.PHONY: build_src_debug

@ -1172,7 +1172,10 @@ int ProxySQL_Test___GenerateRandomQueryInDigestTable(int n) {
//unsigned long long queries=n;
//queries *= 1000;
MySQL_Session *sess = new MySQL_Session();
// When the session is destroyed, client_connections is automatically decreased.
// Because this is not a real connection, we artificially increase
// client_connections
__sync_fetch_and_add(&MyHGM->status.client_connections,1);
sess->client_myds = new MySQL_Data_Stream();
sess->client_myds->fd=0;
sess->client_myds->init(MYDS_FRONTEND, sess, sess->client_myds->fd);

@ -12,6 +12,15 @@
* @date 2021-10-28
*/
/*
NOTE:
Test 4 assumes that no new variable was introduced after
table history_mysql_status_variables was initialized.
If this is not true, manually run the following before running the test:
DELETE FROM history_mysql_status_variables;
*/
#include <algorithm>
#include <string>
#include <stdio.h>

@ -13,6 +13,12 @@
* any error reported by the client due to broken connections.
*/
/*
NOTE: the parameters in this test are tuned in a way that if proxysql starts
with only 1 worker thread, it is unlikely to ping all connections on time.
See note on wait_timeout
*/
#include <string>
#include <vector>
#include <map>
@ -33,6 +39,45 @@ using std::pair;
using srv_cfg = vector<pair<string,int>>;
int wait_timeout = 10;
// if only 1 worker thread is running, wait_timeout should be bigger
// 1 worker thread : wait_timeout = 45
// 4 worker threads : wait_timeout = 10
int compute_wait_timeout(MYSQL *my_conn) {
int res = EXIT_SUCCESS;
res = mysql_query(my_conn, "SELECT @@mysql-threads");
if (res != EXIT_SUCCESS) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn));
res = EXIT_FAILURE;
return res;
}
MYSQL_RES* my_res = mysql_store_result(my_conn);
if (my_res == nullptr) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn));
res = EXIT_FAILURE;
return res;
}
MYSQL_ROW row = mysql_fetch_row(my_res);
if (row == nullptr || row[0] == nullptr) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn));
res = EXIT_FAILURE;
return res;
} else {
const char *val = row[0];
diag("mysql-threads = %s", val);
if (strcmp(val,"1")==0) {
diag("Setting wait_timeout to 45 instead of 10");
wait_timeout = 45;
}
}
mysql_free_result(my_res);
return res;
}
int change_mysql_cfg(
const CommandLine& cl, const string& host, const string& port, const srv_cfg& new_srv_cfg, srv_cfg& out_old_srv_cfg
) {
@ -78,7 +123,9 @@ int change_mysql_cfg(
mysql_free_result(my_res);
mysql_query(my_conn, string { "SET GLOBAL " + config_var.first + "=" + std::to_string(config_var.second) }.c_str());
string query = string { "SET GLOBAL " + config_var.first + "=" + std::to_string(config_var.second) };
diag("Setting on %s:%s : %s", host.c_str(), port.c_str(), query.c_str());
mysql_query(my_conn, query.c_str());
if (res != EXIT_SUCCESS) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn));
res = EXIT_FAILURE;
@ -337,6 +384,7 @@ int wait_target_backend_conns(MYSQL* admin, uint32_t tg_backend_conns, uint32_t
break;
} else {
waited += 1;
diag("tg_backend_conns: %d, cur_conn_num: %ld , not matching after %lu checks", tg_backend_conns, cur_conn_num, waited);
sleep(1);
}
}
@ -387,6 +435,10 @@ int main(int, char**) {
return EXIT_FAILURE;
}
if (compute_wait_timeout(proxy_admin) != EXIT_SUCCESS) {
return EXIT_FAILURE;
}
double intv = 5;
double b = 128;
double b_0 = 256;
@ -416,15 +468,22 @@ int main(int, char**) {
MYSQL_QUERY(proxy_admin, "LOAD MYSQL SERVERS TO RUNTIME");
diag("Setting ProxySQL config...");
// Set the backend connections ping frequency
MYSQL_QUERY(proxy_admin, string { "SET mysql-ping_interval_server_msec=" + std::to_string(freq) }.c_str());
// Make sure no connection cleanup takes place
MYSQL_QUERY(proxy_admin, "SET mysql-free_connections_pct=100");
// Don't retry on failure
MYSQL_QUERY(proxy_admin, "SET mysql-query_retries_on_failure=0");
// Set a higher max_connection number for the servers
MYSQL_QUERY(proxy_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
{
// Set the backend connections ping frequency
string query = string { "SET mysql-ping_interval_server_msec=" + std::to_string(freq) };
diag("%s", query.c_str());
MYSQL_QUERY(proxy_admin, query.c_str());
// Make sure no connection cleanup takes place
query = "SET mysql-free_connections_pct=100";
diag("%s", query.c_str());
MYSQL_QUERY(proxy_admin, query.c_str());
// Don't retry on failure
query = "SET mysql-query_retries_on_failure=0";
diag("%s", query.c_str());
MYSQL_QUERY(proxy_admin, query.c_str());
// Set a higher max_connection number for the servers
MYSQL_QUERY(proxy_admin, "LOAD MYSQL VARIABLES TO RUNTIME");
}
// Configure MySQL infra servers with: 'wait_timeout' and 'max_connections'
vector<pair<mysql_res_row, srv_cfg>> servers_old_configs {};
@ -440,7 +499,7 @@ int main(int, char**) {
return EXIT_FAILURE;
}
srv_cfg new_srv_cfg { { "wait_timeout", 10 }, { "max_connections", 2500 } };
srv_cfg new_srv_cfg { { "wait_timeout", wait_timeout }, { "max_connections", 2500 } };
for (const mysql_res_row& srv_row : servers_rows) {
srv_cfg old_srv_cfg {};

Loading…
Cancel
Save