From a999eeddca6242bc2554e70db9fbf683fc1b5260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Sun, 31 Jul 2022 21:17:24 +0200 Subject: [PATCH] Fix 'test_cluster1-t' checksum fetching logic --- test/tap/tests/test_cluster1-t.cpp | 57 +++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/test/tap/tests/test_cluster1-t.cpp b/test/tap/tests/test_cluster1-t.cpp index ce017e985..b3a4526ce 100644 --- a/test/tap/tests/test_cluster1-t.cpp +++ b/test/tap/tests/test_cluster1-t.cpp @@ -77,29 +77,43 @@ int dumping_checksums_return_uniq(MYSQL_RES *res, std::set& checksu return checksums.size(); } +int _get_checksum(MYSQL* mysql, const std::string& name, std::string& value) { + std::string query { "SELECT checksum FROM runtime_checksums_values WHERE name='" + name + "'" }; + + if (mysql_query(mysql, query.c_str())) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); + return -1; + } -int get_checksum(MYSQL *mysql, const std::string& name, std::string& value) { - std::string query = "SELECT checksum FROM runtime_checksums_values WHERE name='" + name + "'"; - MYSQL_QUERY(mysql,query.c_str()); MYSQL_RES * res = mysql_store_result(mysql); int rr = mysql_num_rows(res); MYSQL_ROW row; while ((row = mysql_fetch_row(res))) { value = std::string(row[0]); } - ok(rr == 1 && value.length() > 0, "Checksum for %s = %s" , name.c_str(), value.c_str()); mysql_free_result(res); + + return rr; +} + +int get_checksum(MYSQL *mysql, const std::string& name, std::string& value) { + int rr = _get_checksum(mysql, name, value); + ok(rr == 1 && value.length() > 0, "Checksum for %s = %s" , name.c_str(), value.c_str()); if (rr == 1 && value.length() > 0) return 0; return 1; } -int module_in_sync(MYSQL *mysql, const std::string& name, const std::string& value, int num_retries, int& i) { +int module_in_sync( + MYSQL* tg_admin, MYSQL* fetch_conn, const std::string& name, const std::string& init_chk, int num_retries, int& i +) { std::string query = "SELECT hostname, port, name, version, epoch, checksum, changed_at, updated_at, diff_check FROM stats_proxysql_servers_checksums WHERE name='" + name + "'"; + std::string checksum { init_chk }; int rc = 0; + while (i< num_retries && rc != 1) { std::set checksums; - MYSQL_QUERY(mysql,query.c_str()); - MYSQL_RES * res = mysql_store_result(mysql); + MYSQL_QUERY(tg_admin, query.c_str()); + MYSQL_RES * res = mysql_store_result(tg_admin); std::string s; get_time(s); diag("%s: Dumping %s", s.c_str(), query.c_str()); @@ -107,13 +121,21 @@ int module_in_sync(MYSQL *mysql, const std::string& name, const std::string& val mysql_free_result(res); if (rc == 1) { std::set::iterator it = checksums.begin(); - if (*it == value) { + if (*it == checksum) { return 0; + } else { + int chk_res = _get_checksum(fetch_conn, name, checksum); + if (chk_res != -1) { + diag("Fetched new '%s' target checksum '%s'", name.c_str(), checksum.c_str()); + } else { + diag("Fetching new checksum for module '%s' failed", name.c_str()); + } } } sleep(1); i++; } + return 1; } @@ -145,12 +167,12 @@ int trigger_sync_and_check(MYSQL *mysql, std::string modname, const char *update get_checksum(mysql, modname, chk2); ok(chk1 != chk2 , "%s checksums. Before: %s , after: %s", modname.c_str(), chk1.c_str(), chk2.c_str()); int retries = 0; - rc = module_in_sync(mysql, modname, chk2, 30, retries); + rc = module_in_sync(mysql, mysql, modname, chk2, 30, retries); ok (rc == 0, "Module %s %sin sync after %d seconds" , modname.c_str() , rc == 0 ? "" : "NOT " , retries); for (int i = 4 ; i