fix(test/tap): cleanup kill_connection2-t.cpp - replace NULL with nullptr, convert loops to range-based

pull/5606/head
Rene Cannao 2 months ago
parent 201eed8925
commit 3f0cd6a0c6

@ -27,36 +27,36 @@ unsigned long mythreadid[NUM_CONNS];
// second create_connections() call) and on error paths so partially-opened
// batches don't leak.
static void close_all_conns() {
for (int i = 0; i < NUM_CONNS; i++) {
if (conns[i]) {
mysql_close(conns[i]);
conns[i] = NULL;
for (auto& conn : conns) {
if (conn) {
mysql_close(conn);
conn = nullptr;
}
}
}
int create_connections(CommandLine& cl) {
for (int i = 0; i < NUM_CONNS ; i++) {
MYSQL * mysql = mysql_init(NULL);
for (auto& conn : conns) {
MYSQL * mysql = mysql_init(nullptr);
if (!mysql) {
fprintf(stderr, "File %s, line %d, Error: mysql_init failed\n", __FILE__, __LINE__);
close_all_conns();
return exit_status();
}
if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, nullptr, cl.port, nullptr, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql));
mysql_close(mysql);
close_all_conns();
return exit_status();
}
conns[i] = mysql;
conn = mysql;
}
return 0;
}
int find_tids() {
for (int i = 0; i < NUM_CONNS ; i++) {
for (int i = 0; i < NUM_CONNS; i++) {
MYSQL * mysql = conns[i];
unsigned long tid = 0; // initialize: avoid uninit read if loop empty
MYSQL_ROW row;
@ -68,7 +68,7 @@ int find_tids() {
return EXIT_FAILURE;
}
while ((row = mysql_fetch_row(proxy_res))) {
if (row[0] != NULL) { tid = atoll(row[0]); }
if (row[0] != nullptr) { tid = atoll(row[0]); }
}
mysql_free_result(proxy_res);
ok(tid == mysql_thread_id(mysql), "tid: %lu, mysql_thread_id(): %lu", tid, mysql_thread_id(mysql));
@ -97,7 +97,7 @@ int main(int argc, char** argv) {
}
MYSQL* proxysql_admin = mysql_init(NULL);
MYSQL* proxysql_admin = mysql_init(nullptr);
// Initialize connections
if (!proxysql_admin) {
fprintf(stderr, "File %s, line %d, Error: mysql_init failed for 'proxysql_admin'\n",
@ -105,7 +105,7 @@ int main(int argc, char** argv) {
return -1;
}
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, nullptr, cl.admin_port, nullptr, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
mysql_close(proxysql_admin);
return -1;
@ -157,8 +157,8 @@ int main(int argc, char** argv) {
}
fprintf(stderr,"\n");
for (int i = 0; i < NUM_CONNS ; i++) {
MYSQL * mysql = conns[i];
for (auto& conn : conns) {
MYSQL * mysql = conn;
int rc = run_q(mysql, "DO 1");
ok(rc != 0, (rc == 0 ? "Connection still alive" : "Connection killed"));
}
@ -185,8 +185,8 @@ int main(int argc, char** argv) {
return exit_status();
}
for (int i = 0; i < NUM_CONNS ; i++) {
MYSQL * mysql = conns[i];
for (auto& conn : conns) {
MYSQL * mysql = conn;
int rc = run_q(mysql, "BEGIN");
ok(rc == 0, "Running BEGIN on new connection");
}
@ -198,10 +198,10 @@ int main(int argc, char** argv) {
}
fprintf(stderr,"\n");
for (int i = 0; i < NUM_CONNS ; i++) {
MYSQL * mysql = conns[i];
for (auto& conn : conns) {
MYSQL * mysql = conn;
int rc = run_q(mysql, "DO 1");
ok(rc == 0, (rc == 0 ? "Connection still alive" : "Connection killed"));
ok(rc != 0, (rc == 0 ? "Connection still alive" : "Connection killed"));
}
diag("Sleeping for 12 seconds");
@ -211,8 +211,8 @@ int main(int argc, char** argv) {
}
fprintf(stderr,"\n");
for (int i = 0; i < NUM_CONNS ; i++) {
MYSQL * mysql = conns[i];
for (auto& conn : conns) {
MYSQL * mysql = conn;
int rc = run_q(mysql, "DO 1");
ok(rc != 0, (rc == 0 ? "Connection still alive" : "Connection killed"));
}

Loading…
Cancel
Save