Skip to content

Commit

Permalink
Fix env vars support for 'test_auth_methods-t'
Browse files Browse the repository at this point in the history
- Changed several hardcoded variables in favor of env vars.
- Adopted 'TAP_' convention for env vars.
- Added new file 'test_auth_methods-t.env'.
  • Loading branch information
JavierJF committed Feb 22, 2024
1 parent caed360 commit ab741ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
72 changes: 34 additions & 38 deletions test/tap/tests/test_auth_methods-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
#include "command_line.h"
#include "utils.h"

#define SINGLE_BACKEND_HG 30
// Additional env variables
uint32_t TAP_MYSQL8_BACKEND_HG = 30;
uint32_t TAP_NUM_CLIENT_THREADS = 4;

using std::pair;
using std::string;
Expand Down Expand Up @@ -67,6 +69,9 @@ using std::unique_ptr;
} \
} while(0)

/**
* @brief TODO: Currently unused; move to utilities.
*/
string my_escape_string(MYSQL* mysql, const string& q) {
size_t size = q.size();

Expand Down Expand Up @@ -651,9 +656,9 @@ pair<int,vector<user_creds_t>> config_mysql_backend_users(
return { EXIT_SUCCESS, std::move(f_users_creds) };
}

const string def_hg { std::to_string(30) };

int config_proxysql_users(MYSQL* admin, const test_conf_t& test_conf, const vector<user_creds_t>& users) {
const string DEF_HG { std::to_string(TAP_MYSQL8_BACKEND_HG) };

for (const auto& u : users) {
MYSQL_QUERY_T(admin, ("DELETE FROM mysql_users WHERE username='" + u.user_def.name + "'").c_str());
}
Expand Down Expand Up @@ -682,9 +687,7 @@ int config_proxysql_users(MYSQL* admin, const test_conf_t& test_conf, const vect
addl_pass = u.user_def.addl_pass.get();
}

const string esc_addl_pass { my_escape_string(admin, addl_pass) };
const string hex_addl_pass { hex(addl_pass) };

attrs = "{\"additional_password\": \"" + hex_addl_pass + "\"}";
}

Expand All @@ -700,18 +703,18 @@ int config_proxysql_users(MYSQL* admin, const test_conf_t& test_conf, const vect
if (u.user_def.addl_pass) {
insert_query = {
"INSERT INTO mysql_users (username,password,default_hostgroup,attributes) "
"VALUES ('" + u.user_def.name + "'," + prim_pass + "," + def_hg + ",'" + attrs + "')"
"VALUES ('" + u.user_def.name + "'," + prim_pass + "," + DEF_HG + ",'" + attrs + "')"
};
} else {
insert_query = {
"INSERT INTO mysql_users (username,password,default_hostgroup) "
"VALUES ('" + u.user_def.name + "'," + prim_pass + "," + def_hg + ")"
"VALUES ('" + u.user_def.name + "'," + prim_pass + "," + DEF_HG + ")"
};
}
} else {
insert_query = {
"INSERT INTO mysql_users (username,default_hostgroup,attributes) "
"VALUES ('" + u.user_def.name + "'," + def_hg + ",'" + attrs + "')"
"VALUES ('" + u.user_def.name + "'," + DEF_HG + ",'" + attrs + "')"
};
}

Expand Down Expand Up @@ -1442,12 +1445,12 @@ int backend_conns_cleanup(MYSQL* admin) {
diag("Cleaning up previous backend connections...");
MYSQL_QUERY(admin,
("UPDATE mysql_servers SET max_connections=0 "
"WHERE hostgroup_id=" + std::to_string(SINGLE_BACKEND_HG)).c_str()
"WHERE hostgroup_id=" + std::to_string(TAP_MYSQL8_BACKEND_HG)).c_str()
);
MYSQL_QUERY(admin, "LOAD MYSQL SERVERS TO RUNTIME");

// Wait for backend connection cleanup
int w_res = wait_target_backend_conns(admin, 0, 10, SINGLE_BACKEND_HG);
int w_res = wait_target_backend_conns(admin, 0, 10, TAP_MYSQL8_BACKEND_HG);
if (w_res != EXIT_SUCCESS) {
diag("Waiting for backend connections failed res:'%d'", w_res);
return EXIT_FAILURE;
Expand All @@ -1456,7 +1459,7 @@ int backend_conns_cleanup(MYSQL* admin) {
diag("Setup new connection limit max_connections='2000'");
MYSQL_QUERY(admin,
("UPDATE mysql_servers SET max_connections=2000 "
"WHERE hostgroup_id=" + std::to_string(SINGLE_BACKEND_HG)).c_str()
"WHERE hostgroup_id=" + std::to_string(TAP_MYSQL8_BACKEND_HG)).c_str()
);
MYSQL_QUERY(admin, "LOAD MYSQL SERVERS TO RUNTIME");

Expand Down Expand Up @@ -1515,7 +1518,6 @@ bool req_sha2_auth(const test_conf_t& conf, const test_creds_t& creds) {
int test_confs_creds_combs_frontend(
CommandLine& cl,
MYSQL* admin,
const uint64_t NUM_CLIENT_THREADS,
const vector<user_creds_t>& user_creds,
const vector<pair<test_conf_t, vector<test_creds_t>>>& confs_creds_map,
const chk_exp_scs_t& chk_exp_scs
Expand All @@ -1538,7 +1540,7 @@ int test_confs_creds_combs_frontend(
std::vector<std::thread> client_threads {};

// Perform parallel fronted logging tests
for (uint32_t i = 0; i < NUM_CLIENT_THREADS; i++) {
for (uint32_t i = 0; i < TAP_NUM_CLIENT_THREADS; i++) {
client_threads.push_back(std::thread([&cl, &p_conf_creds, &chk_exp_scs] () {
for (const auto& creds : p_conf_creds.second) {
test_creds_frontend(cl, p_conf_creds.first, creds, chk_exp_scs);
Expand All @@ -1557,7 +1559,6 @@ int test_confs_creds_combs_frontend(
int test_all_confs_creds(
CommandLine& cl,
MYSQL* admin,
const uint64_t NUM_CLIENT_THREADS,
const vector<test_conf_t>& all_conf_combs,
const vector<user_creds_t>& users_creds,
const vector<test_creds_t>& tests_creds,
Expand All @@ -1583,14 +1584,14 @@ int test_all_confs_creds(
MYSQL_QUERY_T(admin, "LOAD MYSQL USERS TO RUNTIME");

std::vector<std::thread> client_thds {};
std::vector<uint64_t> thds_exp_sha2_auths(NUM_CLIENT_THREADS);
std::vector<uint64_t> thds_exp_sha2_auths(TAP_NUM_CLIENT_THREADS);
std::vector<auth_reg_t> thds_auth_regs {};

for (uint32_t i = 0; i < NUM_CLIENT_THREADS; i++) {
for (uint32_t i = 0; i < TAP_NUM_CLIENT_THREADS; i++) {
thds_auth_regs.push_back(create_auth_reg(users_creds));
}

for (uint32_t i = 0; i < NUM_CLIENT_THREADS; i++) {
for (uint32_t i = 0; i < TAP_NUM_CLIENT_THREADS; i++) {
client_thds.push_back(
std::thread(
[&cl, &conf, &thds_auth_regs, &thds_exp_sha2_auths, i, &users_creds, &tests_creds] () {
Expand Down Expand Up @@ -1626,7 +1627,7 @@ int test_all_confs_creds(
cthread.join();
}

for (uint32_t i = 0; i < NUM_CLIENT_THREADS; i++) {
for (uint32_t i = 0; i < TAP_NUM_CLIENT_THREADS; i++) {
auth_reg_t& auth_reg { thds_auth_regs[i] };

for (const auto& auth_stats : auth_reg) {
Expand All @@ -1639,7 +1640,7 @@ int test_all_confs_creds(
}
}

uint64_t exp_scs_total = non_warmup_tests_scs_count * NUM_CLIENT_THREADS;
uint64_t exp_scs_total = non_warmup_tests_scs_count * TAP_NUM_CLIENT_THREADS;
uint64_t exp_full_sha2_total = exp_sha2_auths;

ok(
Expand All @@ -1665,6 +1666,9 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}

TAP_MYSQL8_BACKEND_HG = get_env_int("TAP_MYSQL8_BACKEND_HG", 30);
TAP_NUM_CLIENT_THREADS = get_env_int("TAP_NUM_CLIENT_THREADS", 4);

MYSQL* mysql = mysql_init(NULL);

if (!mysql_real_connect(mysql, cl.host, cl.mysql_username, cl.mysql_password, NULL, cl.mysql_port, NULL, 0)) {
Expand Down Expand Up @@ -1748,7 +1752,7 @@ int main(int argc, char** argv) {

pair<uint64_t,uint64_t> rnd_scs_stats {};

if (getenv("DISABLE_SEQ_CHECKS_RAND_PASS") == nullptr) {
if (getenv("TAP_DISABLE_SEQ_CHECKS_RAND_PASS") == nullptr) {
rnd_scs_stats = count_exp_scs(all_conf_combs, rnd_cbres.second, rnd_tests_creds);
}

Expand All @@ -1762,23 +1766,23 @@ int main(int argc, char** argv) {

uint64_t non_warmup_tests_fail_count = 0;

if (getenv("DISABLE_NON_WARMUP_EXP_FAILS") == nullptr) {
if (getenv("TAP_DISABLE_NON_WARMUP_EXP_FAILS") == nullptr) {
for (const auto& p_conf_creds : non_warmup_tests_fail) {
non_warmup_tests_fail_count += p_conf_creds.second.size();
}
}

uint64_t non_warmup_tests_scs_count = 0;

if (getenv("DISABLE_NON_WARMUP_EXP_SCS") == nullptr) {
if (getenv("TAP_DISABLE_NON_WARMUP_EXP_SCS") == nullptr) {
for (const auto& p_conf_creds : non_warmup_tests_scs) {
non_warmup_tests_scs_count += p_conf_creds.second.size();
}
}

uint64_t non_warmup_tests_scs_ratio = 0;

if (getenv("DISABLE_NON_WARMUP_EXP_RATIO") == nullptr) {
if (getenv("TAP_DISABLE_NON_WARMUP_EXP_RATIO") == nullptr) {
non_warmup_tests_scs_ratio = 2;
}

Expand Down Expand Up @@ -1813,7 +1817,7 @@ int main(int argc, char** argv) {
}

// sequential; verify correctness in the procedure; RANDOM passwords
if (getenv("DISABLE_SEQ_CHECKS_RAND_PASS") == nullptr) {
if (getenv("TAP_DISABLE_SEQ_CHECKS_RAND_PASS") == nullptr) {
for (const auto& conf : all_conf_combs) {
int rc = backend_conns_cleanup(admin);
if (rc) { goto cleanup; }
Expand All @@ -1837,41 +1841,33 @@ int main(int argc, char** argv) {
}

// concurrent; known to fail tests cases; no previous auths
if (getenv("DISABLE_NON_WARMUP_EXP_FAILS") == nullptr) {
if (getenv("TAP_DISABLE_NON_WARMUP_EXP_FAILS") == nullptr) {
diag("Starting frontend non-warmup FAIL tests; expected all auths to FAIL");

int res = test_confs_creds_combs_frontend(
cl, admin, NUM_CLIENT_THREADS, cbres.second, non_warmup_tests_fail,
int res = test_confs_creds_combs_frontend(cl, admin, cbres.second, non_warmup_tests_fail,
[] (const test_conf_t&, const test_creds_t&) { return false; }
);

if (res) { goto cleanup; }
}

// concurrent; known to succeed tests cases; no previous auths
if (getenv("DISABLE_NON_WARMUP_EXP_SCS") == nullptr) {
if (getenv("TAP_DISABLE_NON_WARMUP_EXP_SCS") == nullptr) {
diag("Starting frontend non-warmup SUCCESS tests; expected all auths to SUCCEED");

int res = test_confs_creds_combs_frontend(
cl, admin, NUM_CLIENT_THREADS, cbres.second, non_warmup_tests_scs,
int res = test_confs_creds_combs_frontend(cl, admin, cbres.second, non_warmup_tests_scs,
[] (const test_conf_t&, const test_creds_t&) { return true; }
);

if (res) { goto cleanup; }
}

// concurrent; warmup phase; only number of succeed/failures is pre-known
if (getenv("DISABLE_NON_WARMUP_EXP_RATIO") == nullptr) {
if (getenv("TAP_DISABLE_NON_WARMUP_EXP_RATIO") == nullptr) {
diag("Starting frontend non-warmup ALL_COMBS tests; predicting SUCCESS/FAILURE ratio");

int res = test_all_confs_creds(
cl,
admin,
NUM_CLIENT_THREADS,
all_conf_combs,
cbres.second,
tests_creds,
non_warmup_tests_scs_count
cl, admin, all_conf_combs, cbres.second, tests_creds, non_warmup_tests_scs_count
);

if (res) { goto cleanup; }
Expand Down
6 changes: 6 additions & 0 deletions test/tap/tests/test_auth_methods-t.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TAP_MYSQLUSERNAME=root
TAP_MYSQLPASSWORD=root
TAP_MYSQLPORT=14806

TAP_MYSQL8_BACKEND_HG=30
TAP_NUM_CLIENT_THREADS=4

0 comments on commit ab741ee

Please sign in to comment.