Skip to content

Commit

Permalink
Merge branch 'v2.x-tap_tests_opt_ssl' of https://github.com/mirostaud…
Browse files Browse the repository at this point in the history
…er/proxysql into v2.x-tap_tests_opt_ssl
  • Loading branch information
mirostauder committed Sep 28, 2023
2 parents 20d6152 + ad341b8 commit 6b414c7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 30 deletions.
43 changes: 35 additions & 8 deletions test/tap/tests/charset_unsigned_int-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
int main(int argc, char** argv) {
CommandLine cl;

plan(2 + 2 + 6);
plan(2+2+2+2+2 + 6);
diag("Testing correct collation set with proxysql");

std::string var_collation_connection = "collation_connection";
Expand Down Expand Up @@ -78,8 +78,17 @@ int main(int argc, char** argv) {
/* Check that default collation can be configures through admin */
std::string var_name="mysql-default_charset";
MYSQL * mysql_a = mysql_init(NULL);
if (!mysql) return exit_status();
if (!mysql_real_connect(mysql_a, cl.host, "admin", "admin", NULL, 6032, NULL, 0)) return exit_status();
diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d", cl.admin_username, cl.use_ssl);
if (cl.use_ssl)
mysql_ssl_set(mysql_a, NULL, NULL, NULL, NULL, NULL);
if (!mysql_real_connect(mysql_a, cl.admin_host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql_a));
return -1;
} else {
const char * c = mysql_get_ssl_cipher(mysql_a);
ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c);
ok(mysql_a->net.compress == 0, "Compression: (%d)", mysql_a->net.compress);
}

if (mysql_query(mysql_a, "update global_variables set variable_value='latin1' where variable_name='mysql-default_charset'")) return exit_status();
if (mysql_query(mysql_a, "load mysql variables to runtime")) return exit_status();
Expand All @@ -99,8 +108,17 @@ int main(int argc, char** argv) {


MYSQL* mysql_b = mysql_init(NULL);
if (!mysql_b) return exit_status();
if (!mysql_real_connect(mysql_b, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) return exit_status();
diag("Connecting: cl.username='%s' cl.use_ssl=%d", cl.username, cl.use_ssl);
if (cl.use_ssl)
mysql_ssl_set(mysql_b, NULL, NULL, NULL, NULL, NULL);
if (!mysql_real_connect(mysql_b, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql_b));
return -1;
} else {
const char * c = mysql_get_ssl_cipher(mysql_b);
ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c);
ok(mysql_b->net.compress == 0, "Compression: (%d)", mysql_b->net.compress);
}

get_server_version(mysql_b, version);
if (version.data()[0] == '5') {
Expand All @@ -118,9 +136,18 @@ int main(int argc, char** argv) {
//set_admin_global_variable(proxysql_admin, "mysql-default_collation_connection", "utf8mb4_general_ci");
//if (mysql_query(proxysql_admin, "load mysql variables to runtime")) return exit_status();
MYSQL * mysql_c = mysql_init(NULL);
if (!mysql_c) return exit_status();
if (mysql_options(mysql_c, MYSQL_SET_CHARSET_NAME, "utf8mb4")) return exit_status();
if (!mysql_real_connect(mysql_c, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) return exit_status();
diag("Connecting: cl.username='%s' cl.use_ssl=%d", cl.username, cl.use_ssl);
mysql_options(mysql_c, MYSQL_SET_CHARSET_NAME, "utf8mb4");
if (cl.use_ssl)
mysql_ssl_set(mysql_c, NULL, NULL, NULL, NULL, NULL);
if (!mysql_real_connect(mysql_c, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql_c));
return -1;
} else {
const char * c = mysql_get_ssl_cipher(mysql_c);
ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c);
ok(mysql_c->net.compress == 0, "Compression: (%d)", mysql_c->net.compress);
}

if (get_server_version(mysql_c, version)) return exit_status();
if (version.data()[0] == '5') {
Expand Down
2 changes: 1 addition & 1 deletion test/tap/tests/set_testing-multi-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ int main(int argc, char *argv[]) {
// host = cl.host;
// port = cl.port;

plan(2 + queries * num_threads);
plan(2 + 2*queries_per_connections*count + queries * num_threads);
if (!readTestCases(fileName)) {
fprintf(stderr, "Cannot read %s\n", fileName.c_str());
return exit_status();
Expand Down
9 changes: 6 additions & 3 deletions test/tap/tests/test_binlog_fast_forward-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,18 @@ int setup_replication(int server_id, bool frontend_ssl, bool backend_ssl, std::v

std::vector<std::string> admin_queries = {};
admin_queries.push_back(std::string("SET mysql-have_ssl='") + std::string(frontend_ssl ? "true" : "false") + "'");
admin_queries.push_back(std::string("UPDATE mysql_users SET use_ssl=") + std::string(frontend_ssl ? "1" : "0") + " WHERE username = 'root'");
admin_queries.push_back("LOAD MYSQL VARIABLES TO RUNTIME");
admin_queries.push_back(std::string("UPDATE mysql_servers SET use_ssl=") + std::string(backend_ssl ? "1" : "0"));
admin_queries.push_back("LOAD MYSQL SERVERS TO RUNTIME");

MYSQL * mysql = mysql_init(NULL);
diag("Connecting: cl.root_username='%s' frontend_ssl=%d", cl.root_username,frontend_ssl);
if (frontend_ssl)
diag("Connecting: cl.root_username='%s' frontend_ssl=%d", cl.root_username, frontend_ssl);
if (frontend_ssl || backend_ssl) {
mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL);
if (!mysql_real_connect(mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) {
diag(">>> 'mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL);' <<<");
}
if (!mysql_real_connect(mysql, cl.host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) {
fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql));
return exit_status();
} else {
Expand Down
26 changes: 11 additions & 15 deletions test/tap/tests/test_query_rules_fast_routing_algorithm-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "json.hpp"


CommandLine cl;

using std::pair;
using std::string;
using nlohmann::json;
Expand Down Expand Up @@ -141,19 +144,17 @@ string get_last_debug_log_id(sqlite3* sq3_db) {
return last_id_rows[0][0];
}

int create_mysql_servers_range(
const CommandLine& cl, MYSQL* admin, const pair<string,int>& host_port, uint32_t rng_init, uint32_t rng_end
) {
int create_mysql_servers_range(MYSQL* admin, const pair<string,int>& host_port, uint32_t rng_init, uint32_t rng_end) {
const string init { std::to_string(rng_init) };
const string end { std::to_string(rng_end) };

MYSQL_QUERY_T(admin, ("DELETE FROM mysql_servers WHERE hostgroup_id BETWEEN " + init + " AND " + end).c_str());

for (uint32_t i = rng_init; i < rng_end; i += 2) {
std::string q = "INSERT INTO mysql_servers (hostgroup_id, hostname, port) VALUES ";
q += "(" + std::to_string(i) + ",'" + host_port.first + "'," + std::to_string(host_port.second) + ")";
std::string q = "INSERT INTO mysql_servers (hostgroup_id, hostname, port, use_ssl) VALUES ";
q += "(" + std::to_string(i) + ",'" + host_port.first + "'," + std::to_string(host_port.second) + "," + std::to_string(cl.use_ssl) + ")";
q += ",";
q += "(" + std::to_string(i+1) + ",'" + host_port.first + "'," + std::to_string(host_port.second) + ")";
q += "(" + std::to_string(i+1) + ",'" + host_port.first + "'," + std::to_string(host_port.second) + "," + std::to_string(cl.use_ssl) + ")";
MYSQL_QUERY(admin, q.c_str());
}

Expand Down Expand Up @@ -200,10 +201,7 @@ int sq3_get_matching_msg_entries(sqlite3* db, const string& query_regex, const s
return matching_rows;
};

int test_fast_routing_algorithm(
const CommandLine& cl, MYSQL* admin, MYSQL* proxy, const pair<string,int>& host_port, fstream& errlog,
int init_algo, int new_algo
) {
int test_fast_routing_algorithm(MYSQL* admin, MYSQL* proxy, const pair<string,int>& host_port, fstream& errlog, int init_algo, int new_algo) {
uint32_t rng_init = 1000;
uint32_t rng_end = 1020;
const char query_rules_mem_stats_query[] {
Expand All @@ -223,7 +221,7 @@ int test_fast_routing_algorithm(

int odb_err = open_sqlite3_db(db_path, &sq3_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
if (odb_err) { return EXIT_FAILURE; }
int c_err = create_mysql_servers_range(cl, admin, host_port, rng_init, rng_end);
int c_err = create_mysql_servers_range(admin, host_port, rng_init, rng_end);
if (c_err) { return EXIT_FAILURE; }
MYSQL_QUERY_T(admin, "LOAD MYSQL SERVERS TO RUNTIME");

Expand Down Expand Up @@ -390,8 +388,6 @@ int main(int argc, char** argv) {
// `5` logic checks + 20*3 checks per query rule, per test
plan(2+2 + (8 + 20*3) * 2);

CommandLine cl;

MYSQL* proxy = mysql_init(NULL);
diag("Connecting: cl.username='%s' cl.use_ssl=%d", cl.username, cl.use_ssl);
if (cl.use_ssl)
Expand Down Expand Up @@ -441,10 +437,10 @@ int main(int argc, char** argv) {
goto cleanup;
}

int test_err = test_fast_routing_algorithm(cl, admin, proxy, host_port, errlog, 1, 2);
int test_err = test_fast_routing_algorithm(admin, proxy, host_port, errlog, 1, 2);
if (test_err) { goto cleanup; }

test_err = test_fast_routing_algorithm(cl, admin, proxy, host_port, errlog, 2, 1);
test_err = test_fast_routing_algorithm(admin, proxy, host_port, errlog, 2, 1);
if (test_err) { goto cleanup; }
}

Expand Down
6 changes: 3 additions & 3 deletions test/tap/tests/test_sqlite3_server_and_fast_routing-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ int benchmark_query_rules_fast_routing(MYSQL* proxysql_admin, MYSQL* proxysql_my
diag("Executing: %s", s.c_str());
MYSQL_QUERY(proxysql_admin, s.c_str());
for (unsigned int i=1001; i<3000; i+=2) {
std::string s = "INSERT INTO mysql_servers (hostgroup_id, hostname, port) VALUES ";
s += "(" + std::to_string(i) + ",'" + host_port.first + "'," + std::to_string(host_port.second) + ")";
std::string s = "INSERT INTO mysql_servers (hostgroup_id, hostname, port, use_ssl) VALUES ";
s += "(" + std::to_string(i) + ",'" + host_port.first + "'," + std::to_string(host_port.second) + "," + std::to_string(cl.use_ssl) + ")";
s += ",";
s += "(" + std::to_string(i+1) + ",'" + host_port.first + "'," + std::to_string(host_port.second) + ")";
s += "(" + std::to_string(i+1) + ",'" + host_port.first + "'," + std::to_string(host_port.second) + "," + std::to_string(cl.use_ssl) + ")";
MYSQL_QUERY(proxysql_admin, s.c_str());
s = "INSERT INTO mysql_query_rules_fast_routing (username, schemaname, flagIN, destination_hostgroup, comment) VALUES ";
s += "('" + std::string(cl.username) + "', 'randomschemaname" + std::to_string(i) + "', 0, " + std::to_string(i) + ", 'writer" + std::to_string(i) + "')";
Expand Down

0 comments on commit 6b414c7

Please sign in to comment.