Skip to content

Commit

Permalink
use 'CommandLine cl' as a TAP test global
Browse files Browse the repository at this point in the history
  • Loading branch information
mirostauder committed Oct 20, 2023
1 parent 076ca2e commit f06c109
Show file tree
Hide file tree
Showing 152 changed files with 785 additions and 978 deletions.
4 changes: 3 additions & 1 deletion test/tap/tap/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,9 @@ string tap_curtime() {
return s;
}

int get_proxysql_cpu_usage(const CommandLine& cl, uint32_t intv, double& cpu_usage) {
int get_proxysql_cpu_usage(uint32_t intv, double& cpu_usage) {
// cl must be a TAP test global
extern CommandLine& cl;
// check if proxysql process is consuming higher cpu than it should
MYSQL* proxysql_admin = mysql_init(NULL);
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
Expand Down
2 changes: 1 addition & 1 deletion test/tap/tap/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ std::string tap_curtime();
* 'ms' in the specified interval.
* @return 0 if success, -1 in case of error.
*/
int get_proxysql_cpu_usage(const CommandLine& cl, uint32_t intv, double& cpu_usage);
int get_proxysql_cpu_usage(uint32_t intv, double& cpu_usage);

/**
* @brief Helper struct holding connection options for helper functions creating MySQL connections.
Expand Down
3 changes: 2 additions & 1 deletion test/tap/tests/admin-listen_on_unix-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

using std::string;

CommandLine cl;

std::string get_admin_mysql_ifaces(MYSQL *admin) {
std::string ret = "";
const char * query = (const char *)"SELECT variable_value FROM runtime_global_variables WHERE variable_name='admin-mysql_ifaces';";
Expand Down Expand Up @@ -41,7 +43,6 @@ std::string get_admin_mysql_ifaces(MYSQL *admin) {


int main(int argc, char** argv) {
CommandLine cl;

plan(2+2 + 13);

Expand Down
3 changes: 2 additions & 1 deletion test/tap/tests/admin_show_create_table-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

using std::string;

CommandLine cl;

/* this test:
* enables mysql-have_ssl
* retrieves all tables in the most important schemas
* for each table, it connects with SSL *and* compression, then retrieves all rows
*/

int main() {
CommandLine cl;

MYSQL* proxysql_admin = mysql_init(NULL);
diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression);
Expand Down
3 changes: 2 additions & 1 deletion test/tap/tests/admin_show_fields_from-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

using std::string;

CommandLine cl;

/* this test:
* enables mysql-have_ssl
* retrieves all tables in the most important schemas
*/

int main() {
CommandLine cl;

MYSQL* proxysql_admin = mysql_init(NULL);
diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression);
Expand Down
3 changes: 2 additions & 1 deletion test/tap/tests/admin_show_table_status-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

using std::string;

CommandLine cl;

/* this test:
* enables mysql-have_ssl
* retrieves all tables in the most important schemas
*/

int main() {
CommandLine cl;

MYSQL* proxysql_admin = mysql_init(NULL);
diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression);
Expand Down
3 changes: 2 additions & 1 deletion test/tap/tests/admin_various_commands-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

using std::string;

CommandLine cl;

/* this test:
* enables mysql-have_ssl
* retrieves all tables in the most important schemas
*/

int main() {
CommandLine cl;

MYSQL* proxysql_admin = mysql_init(NULL);
diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression);
Expand Down
3 changes: 2 additions & 1 deletion test/tap/tests/admin_various_commands2-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using std::string;

CommandLine cl;

/* this test:
* enables mysql-have_ssl
* execute various command
Expand Down Expand Up @@ -108,7 +110,6 @@ int run_q(MYSQL *mysql, const char *q) {
return 0;
}
int main() {
CommandLine cl;

MYSQL* proxysql_admin = mysql_init(NULL);
diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression);
Expand Down
4 changes: 2 additions & 2 deletions test/tap/tests/admin_various_commands3-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using std::string;

CommandLine cl;

/* this test:
* enables mysql-have_ssl
* execute various command
Expand Down Expand Up @@ -42,11 +44,9 @@ int run_q(MYSQL *mysql, const char *q) {
return 0;
}
int main() {
CommandLine cl;

srandom(123);


for (auto it = vals.begin() ; it != vals.end() ; it++) {
std::string q = "PROXYSQLTEST 1 " + std::to_string(*it);
queries.push_back(q);
Expand Down
25 changes: 14 additions & 11 deletions test/tap/tests/basic-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@

#include <stdlib.h>
#include "tap.h"
#include "command_line.h"

CommandLine cl;

int main() {
plan(5);
ok(1 == 1, "testing basic functions");
ok(2 == 2, " ");
ok1(3 == 3);
if (1 == 1)
skip(2, "Sensa fragoli");
else {
ok(1 == 2, "Should not be run at all");
ok(1, "This one neither");
}
return exit_status();
plan(5);
ok(1 == 1, "testing basic functions");
ok(2 == 2, " ");
ok1(3 == 3);
if (1 == 1) {
skip(2, "Sensa fragoli");
} else {
ok(1 == 2, "Should not be run at all");
ok(1, "This one neither");
}
return exit_status();
}

3 changes: 2 additions & 1 deletion test/tap/tests/charset_unsigned_int-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#include "command_line.h"
#include "utils.h"

CommandLine cl;

int main(int argc, char** argv) {
CommandLine cl;

plan(2+2+2+2+2 + 6);
diag("Testing correct collation set with proxysql");
Expand Down
8 changes: 2 additions & 6 deletions test/tap/tests/envvars-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include "tap.h"
#include "command_line.h"

CommandLine cl;

int main(int argc, char** argv) {
CommandLine cl;

char* value = NULL;

Expand All @@ -19,11 +20,6 @@ int main(int argc, char** argv) {
// echo 'TAP_ENV_VAR2=tests.env' > tests.env
// echo 'TAP_ENV_VAR3=envvars-t.env' > envvars-t.env

if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return -1;
}

plan(3);

value = getenv("TAP_ENV_VAR1");
Expand Down
3 changes: 2 additions & 1 deletion test/tap/tests/firewall_commands1-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using std::string;

CommandLine cl;

/* this test:
* enables mysql-have_ssl
* execute various command
Expand Down Expand Up @@ -56,7 +58,6 @@ int run_q(MYSQL *mysql, const char *q) {
return 0;
}
int main() {
CommandLine cl;

MYSQL* proxysql_admin = mysql_init(NULL);
diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression);
Expand Down
2 changes: 1 addition & 1 deletion test/tap/tests/kill_connection-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "command_line.h"
#include "utils.h"

CommandLine cl;

/*
This test verifies a variety of things:
Expand All @@ -28,7 +29,6 @@ int run_q(MYSQL *mysql, const char *q) {
}

int main(int argc, char** argv) {
CommandLine cl;

int np = 0;
np += 2 * NUM_CONNS; // connections
Expand Down
8 changes: 4 additions & 4 deletions test/tap/tests/kill_connection2-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "command_line.h"
#include "utils.h"

CommandLine cl;

/*
This test verifies that client connections are dropped because of:
Expand All @@ -26,7 +27,7 @@ int run_q(MYSQL *mysql, const char *q) {
MYSQL * conns[NUM_CONNS];
unsigned long mythreadid[NUM_CONNS];

int create_connections(CommandLine& cl) {
int create_connections() {
for (int i = 0; i < NUM_CONNS ; i++) {

MYSQL * mysql = mysql_init(NULL);
Expand Down Expand Up @@ -68,7 +69,6 @@ int find_tids() {
}

int main(int argc, char** argv) {
CommandLine cl;

int np = 2;
np += 2 * NUM_CONNS ; // connection
Expand Down Expand Up @@ -105,7 +105,7 @@ int main(int argc, char** argv) {
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");

int rc = 0;
rc = create_connections(cl);
rc = create_connections();
if (rc != 0) {
return exit_status();
}
Expand Down Expand Up @@ -147,7 +147,7 @@ int main(int argc, char** argv) {
MYSQL_QUERY(proxysql_admin, "SET mysql-max_transaction_time=17000"); // to force a close on transaction
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");

rc = create_connections(cl);
rc = create_connections();
if (rc != 0) {
return exit_status();
}
Expand Down
13 changes: 4 additions & 9 deletions test/tap/tests/kill_connection3-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "command_line.h"
#include "utils.h"

CommandLine cl;

/*
This test verifies that client connections are dropped because of:
Expand All @@ -26,7 +27,7 @@ int run_q(MYSQL *mysql, const char *q) {
MYSQL * conns[NUM_CONNS];
unsigned long mythreadid[NUM_CONNS];

int create_connections(CommandLine& cl) {
int create_connections() {
for (int i = 0; i < NUM_CONNS ; i++) {

MYSQL * mysql = mysql_init(NULL);
Expand Down Expand Up @@ -68,7 +69,6 @@ int find_tids() {
}

int main(int argc, char** argv) {
CommandLine cl;

int np = 2; // conection admin
np += 2; // for processlist
Expand All @@ -87,11 +87,6 @@ int main(int argc, char** argv) {

plan(np);

if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return -1;
}


MYSQL* proxysql_admin = mysql_init(NULL);
diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression);
Expand All @@ -115,7 +110,7 @@ int main(int argc, char** argv) {

MYSQL_RES* proxy_res;
int rc = 0;
rc = create_connections(cl);
rc = create_connections();
if (rc != 0) {
return exit_status();
}
Expand Down Expand Up @@ -170,7 +165,7 @@ int main(int argc, char** argv) {
MYSQL_QUERY(proxysql_admin, "SET mysql-show_processlist_extended=2");
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME");

rc = create_connections(cl);
rc = create_connections();
if (rc != 0) {
return exit_status();
}
Expand Down
Loading

0 comments on commit f06c109

Please sign in to comment.