From 1902eb5a7b946797a13aa8fb37bfe3218cb60ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 1 Mar 2023 09:05:12 +0000 Subject: [PATCH] More testing in test_max_transaction_time-t IN PROXYSQL SESSION INTERNAL replace transaction_started_at with transaction_time_ms --- lib/MySQL_Session.cpp | 2 +- .../tap/tests/test_max_transaction_time-t.cpp | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 4b2c5dee1..a56b5ef1c 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1096,7 +1096,7 @@ void MySQL_Session::generate_proxysql_internal_session_json(json &j) { j["last_insert_id"] = last_insert_id; j["last_HG_affected_rows"] = last_HG_affected_rows; j["active_transactions"] = active_transactions; - j["transaction_started_at"] = transaction_started_at; + j["transaction_time_ms"] = thread->curtime - transaction_started_at; j["gtid"]["hid"] = gtid_hid; j["gtid"]["last"] = ( strlen(gtid_buf) ? gtid_buf : "" ); j["qpo"]["create_new_connection"] = qpo->create_new_conn; diff --git a/test/tap/tests/test_max_transaction_time-t.cpp b/test/tap/tests/test_max_transaction_time-t.cpp index 054870bcf..1e0311ea9 100644 --- a/test/tap/tests/test_max_transaction_time-t.cpp +++ b/test/tap/tests/test_max_transaction_time-t.cpp @@ -13,6 +13,7 @@ #include "tap.h" #include "utils.h" +#include #include using std::string; @@ -38,15 +39,13 @@ void parse_result_json_column(MYSQL_RES *result, json& j) { int main(int, char**) { CommandLine cl; - plan(NUMQUERIES*2-1); + plan(NUMQUERIES*2+1); if (cl.getEnv()) { diag("Failed to get the required environmental variables."); return EXIT_FAILURE; } - unsigned long long prev_transaction_started_at = 0; - MYSQL* admin = mysql_init(NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); @@ -88,17 +87,21 @@ int main(int, char**) { parse_result_json_column(myres, j); mysql_free_result(myres); int active_transactions = atoi(j["active_transactions"].dump().c_str()); - unsigned long long transaction_started_at = atoll(j["transaction_started_at"].dump().c_str()); - unsigned long long lapse_time = transaction_started_at - prev_transaction_started_at; - lapse_time /= 1000; - prev_transaction_started_at = transaction_started_at; + unsigned long long transaction_time_ms = atoll(j["transaction_time_ms"].dump().c_str()); + transaction_time_ms /= 1000; ok(active_transactions==1, "active_transactions = %d", active_transactions); - if (i != 0) { - ok (lapse_time >= 900 && lapse_time <= 1200, "Transaction time: %llu ms" , lapse_time); - } + ok(transaction_time_ms >= 900 && transaction_time_ms <= 1200, "Transaction time: %llu ms" , transaction_time_ms); MYSQL_QUERY_T(proxy, "COMMIT"); } + + MYSQL_QUERY_T(proxy, "BEGIN"); + diag("Sleeping for 10 seconds so that the transaction times out"); + sleep(10); + diag("Issuing COMMIT : it should fail"); + int query_err = mysql_query(proxy, "COMMIT"); + ok(query_err != 0 && mysql_errno(proxy) == 2013 , "Failed with error code %d : %s" , mysql_errno(proxy), mysql_error(proxy)); + mysql_close(proxy); return exit_status();