|
| 1 | +#include <string> |
| 2 | +#include <string.h> |
| 3 | +#include "mysql.h" |
| 4 | +#include "mysqld_error.h" |
| 5 | +#include "tap.h" |
| 6 | +#include "command_line.h" |
| 7 | +#include "utils.h" |
| 8 | + |
| 9 | +CommandLine cl; |
| 10 | + |
| 11 | +int main() { |
| 12 | + if (cl.getEnv()) { |
| 13 | + diag("Failed to get the required environmental variables."); |
| 14 | + return -1; |
| 15 | + } |
| 16 | + |
| 17 | + const char* p_infra_datadir = std::getenv("REGULAR_INFRA_DATADIR"); |
| 18 | + if (p_infra_datadir == NULL) { |
| 19 | + // quick exit |
| 20 | + plan(1); |
| 21 | + ok(0, "REGULAR_INFRA_DATADIR not defined"); |
| 22 | + return exit_status(); |
| 23 | + } |
| 24 | + |
| 25 | + plan(1); |
| 26 | + |
| 27 | + MYSQL* proxysql_admin = mysql_init(NULL); |
| 28 | + |
| 29 | + // Initialize connection |
| 30 | + if (!proxysql_admin) { |
| 31 | + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); |
| 32 | + return -1; |
| 33 | + } |
| 34 | + |
| 35 | + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { |
| 36 | + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); |
| 37 | + return -1; |
| 38 | + } |
| 39 | + |
| 40 | + const std::string& ca_full_path = std::string(p_infra_datadir) + "/cert-bundle-rnd.pem"; |
| 41 | + diag("Setting mysql-ssl_p2s_ca to '%s'", ca_full_path.c_str()); |
| 42 | + const std::string& set_ssl_p2s_ca = "SET mysql-ssl_p2s_ca='" + ca_full_path + "'"; |
| 43 | + MYSQL_QUERY(proxysql_admin, set_ssl_p2s_ca.c_str()); |
| 44 | + MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); |
| 45 | + diag("Running ProxySQL Test..."); |
| 46 | + if (mysql_query(proxysql_admin, "PROXYSQLTEST 54 1000")) { |
| 47 | + const std::string& error_msg = mysql_error(proxysql_admin); |
| 48 | + if (error_msg.find("Invalid test") != std::string::npos) { |
| 49 | + ok(true, "ProxySQL is not compiled in Debug mode. Skipping test"); |
| 50 | + } else { |
| 51 | + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, error_msg); |
| 52 | + } |
| 53 | + } else { |
| 54 | + const std::string& msg = mysql_info(proxysql_admin); |
| 55 | + const std::size_t start_pos = msg.find("Took "); |
| 56 | + const std::size_t end_pos = msg.find("ms "); |
| 57 | + if (start_pos != std::string::npos && |
| 58 | + end_pos != std::string::npos) { |
| 59 | + uint64_t time = std::stoull(msg.substr(start_pos + 5, end_pos - (start_pos + 5))); |
| 60 | + ok(time < 20000, "Total duration is '%llu ms' should be less than 20 Seconds", time); |
| 61 | + } |
| 62 | + } |
| 63 | + mysql_close(proxysql_admin); |
| 64 | + return exit_status(); |
| 65 | +} |
0 commit comments