@@ -23466,6 +23466,106 @@ static void test_bug25584097() {
2346623466 thd.join();
2346723467}
2346823468
23469+ static void test_get_connect_stage() {
23470+ MYSQL *mysql_async = NULL, *mysql_sync = NULL;
23471+ net_async_status status;
23472+
23473+ myheader("test_get_connect_stage");
23474+
23475+ enum connect_stage cs = mysql_get_connect_stage(mysql_async);
23476+ if (cs != CONNECT_STAGE_INVALID) {
23477+ fprintf(stdout,
23478+ "\n Expected connect_stage to be "
23479+ "CONNECT_STAGE_INVALID for uninitialized mysql");
23480+ exit(1);
23481+ }
23482+
23483+ /* test stages for a nonblocking conneciton */
23484+ if (!(mysql_async = mysql_client_init(NULL))) {
23485+ myerror("mysql_client_init() failed");
23486+ exit(1);
23487+ }
23488+ cs = mysql_get_connect_stage(mysql_async);
23489+ if (cs != CONNECT_STAGE_NOT_STARTED) {
23490+ fprintf(stdout,
23491+ "\n Expected connect_stage to be "
23492+ "CONNECT_STAGE_NET_BEGIN_CONNECT for just initialized connection"
23493+ "but its %d",
23494+ cs);
23495+ exit(1);
23496+ }
23497+
23498+ enum connect_stage cs_prev = cs;
23499+ do {
23500+ status = mysql_real_connect_nonblocking(
23501+ mysql_async, opt_host, opt_user, opt_password, current_db, opt_port,
23502+ opt_unix_socket, CLIENT_MULTI_STATEMENTS);
23503+ cs = mysql_get_connect_stage(mysql_async);
23504+ // Always expect state machine to make forward progress
23505+ if (cs < cs_prev) {
23506+ fprintf(stdout,
23507+ "\n Did not expect connect_stage to be %d, as previous was %d",
23508+ cs, cs_prev);
23509+ exit(1);
23510+ } else if (cs != cs_prev) {
23511+ if (!opt_silent)
23512+ fprintf(stdout,
23513+ "\n Nonblocking connect made transition from stage %d to %d",
23514+ cs_prev, cs);
23515+ }
23516+ cs_prev = cs;
23517+ } while (status == NET_ASYNC_NOT_READY);
23518+ if (status == NET_ASYNC_ERROR) {
23519+ fprintf(stdout, "\n mysql_real_connect_nonblocking() failed. stage:%d", cs);
23520+ exit(1);
23521+ }
23522+
23523+ cs = mysql_get_connect_stage(mysql_async);
23524+ if (cs != CONNECT_STAGE_COMPLETE) {
23525+ fprintf(stdout,
23526+ "\n Expected connect_stage as CONNECT_STAGE_COMPLETE, its %d", cs);
23527+ exit(1);
23528+ }
23529+ if (!opt_silent)
23530+ fprintf(stdout, "\n Nonblocking connect successful. Final stage %d", cs);
23531+
23532+ mysql_close(mysql_async);
23533+
23534+ /* test stages for a blocking conneciton */
23535+ if (!(mysql_sync = mysql_client_init(NULL))) {
23536+ myerror("mysql_client_init() failed");
23537+ exit(1);
23538+ }
23539+ cs = mysql_get_connect_stage(mysql_sync);
23540+ if (cs != CONNECT_STAGE_NOT_STARTED) {
23541+ fprintf(stdout,
23542+ "\n Sync:Expected connect_stage to be "
23543+ "CONNECT_STAGE_NOT_STARTED for just initialized connection"
23544+ "but its %d",
23545+ cs);
23546+ exit(1);
23547+ }
23548+
23549+ if (!opt_silent)
23550+ fprintf(stdout, "\n Starting blocking connect. Starting stage %d", cs);
23551+ if (!(mysql_real_connect(mysql_sync, opt_host, opt_user, opt_password,
23552+ current_db, opt_port, opt_unix_socket, 0))) {
23553+ myerror("connection failed");
23554+ exit(1);
23555+ }
23556+ cs = mysql_get_connect_stage(mysql_sync);
23557+ if (cs != CONNECT_STAGE_COMPLETE) {
23558+ fprintf(stdout,
23559+ "\n Sync:Expected connect_stage as CONNECT_STAGE_COMPLETE, its %d",
23560+ cs);
23561+ exit(1);
23562+ }
23563+ if (!opt_silent)
23564+ fprintf(stdout, "\n Blocking connect successful. Final stage %d", cs);
23565+
23566+ mysql_close(mysql_sync);
23567+ }
23568+
2346923569static struct my_tests_st my_tests[] = {
2347023570 {"test_bug5194", test_bug5194},
2347123571 {"disable_query_logs", disable_query_logs},
@@ -23782,6 +23882,7 @@ static struct my_tests_st my_tests[] = {
2378223882 {"test_wl13128", test_wl13128},
2378323883 {"test_bug25584097", test_bug25584097},
2378423884 {"test_34556764", test_34556764},
23885+ {"test_get_connect_stage", test_get_connect_stage},
2378523886 {nullptr, nullptr}};
2378623887
2378723888static struct my_tests_st *get_my_tests() { return my_tests; }
0 commit comments