Refactor idle session scanning and improve test precision

Code improvements:
- Extract SESS_TO_SCAN_idle_thread constant to header file for better maintainability
- Replace magic number 128 with named constant in idle_thread_to_kill_idle_sessions()
- Improve code readability and consistency in session scanning logic

Test enhancements:
- Add mysql-poll_timeout configuration for more precise timeout testing
- Reduce test sleep times to 13 seconds for faster test execution
- Add diagnostic messages to clearly show timeout configurations in test output
- Ensure tests properly validate timeout enforcement with precise timing

The changes improve code maintainability and make tests more reliable and faster
while maintaining accurate timeout validation.
pull/4901/head
Rene Cannao 5 months ago
parent 0c5e75a064
commit dc4694d656

@ -34,6 +34,8 @@
#define MYSQL_DEFAULT_NET_WRITE_TIMEOUT "60"
#define MYSQL_DEFAULT_MAX_JOIN_SIZE "18446744073709551615"
#define SESS_TO_SCAN_idle_thread 256
extern class MySQL_Variables mysql_variables;
#ifdef IDLE_THREADS

@ -3431,8 +3431,7 @@ __run_skip_1:
* initialized and are accessible within the MySQL Thread.
*/
void MySQL_Thread::idle_thread_to_kill_idle_sessions() {
#define SESS_TO_SCAN 128
if (mysess_idx + SESS_TO_SCAN > mysql_sessions->len) {
if (mysess_idx + SESS_TO_SCAN_idle_thread > mysql_sessions->len) {
mysess_idx=0;
}
unsigned int i;
@ -3440,7 +3439,7 @@ void MySQL_Thread::idle_thread_to_kill_idle_sessions() {
return; // this should never happen
//min_idle = curtime - (unsigned long long)mysql_thread___wait_timeout*1000;
}
for (i=0;i<SESS_TO_SCAN && mysess_idx < mysql_sessions->len; i++) {
for (i=0 ; i < SESS_TO_SCAN_idle_thread && mysess_idx < mysql_sessions->len; i++) {
uint32_t sess_pos=mysess_idx;
MySQL_Session *mysess=(MySQL_Session *)mysql_sessions->index(sess_pos);
unsigned long long effective_wait_timeout = std::min(

@ -58,7 +58,10 @@ int extract_wait_timeout_from_json(const json& j_session, unsigned long long &wa
int test_session_timeout(CommandLine *cl, MYSQL *admin) {
diag("Test: %s", __func__);
diag("Setting mysql-wait_timeout=50000");
MYSQL_QUERY_T(admin, "SET mysql-wait_timeout=50000");
diag("Setting mysql-poll_timeout=500 , required for more precise timeout");
MYSQL_QUERY_T(admin, "SET mysql-poll_timeout=500");
MYSQL_QUERY_T(admin, "LOAD MYSQL VARIABLES TO RUNTIME");
MYSQL* proxy = init_mysql_conn(cl->host, cl->username, cl->password, cl->port);
@ -72,7 +75,7 @@ int test_session_timeout(CommandLine *cl, MYSQL *admin) {
int rc = run_q(proxy, "SET sql_mode=''");
ok(rc == 0, (rc == 0 ? "Connection alive" : "Connection killed"));
sleep(25);
sleep(13);
rc = run_q(proxy, "SET sql_mode=''");
ok(rc != 0, (rc == 0 ? "Connection alive" : "Connection killed"));
@ -85,7 +88,10 @@ int test_session_timeout(CommandLine *cl, MYSQL *admin) {
int test_session_timeout_exceed_global_timeout(CommandLine *cl, MYSQL *admin) {
diag("Test: %s", __func__);
diag("Setting mysql-wait_timeout=10000");
MYSQL_QUERY_T(admin, "SET mysql-wait_timeout=10000");
diag("Setting mysql-poll_timeout=500 , required for more precise timeout");
MYSQL_QUERY_T(admin, "SET mysql-poll_timeout=500");
MYSQL_QUERY_T(admin, "LOAD MYSQL VARIABLES TO RUNTIME");
MYSQL*proxy = init_mysql_conn(cl->host, cl->username, cl->password, cl->port);
@ -99,7 +105,7 @@ int test_session_timeout_exceed_global_timeout(CommandLine *cl, MYSQL *admin) {
int rc = run_q(proxy, "SET sql_mode=''");
ok(rc == 0, (rc == 0 ? "Connection alive" : "Connection killed"));
sleep(15);
sleep(13);
rc = run_q(proxy, "SET sql_mode=''");
ok(rc != 0, (rc == 0 ? "Connection alive" : "Connection killed"));

Loading…
Cancel
Save