#
# Debug build tests for INFORMATION_SCHEMA.GLOBAL_TEMPORARY_TABLES
#
--source include/have_debug.inc
--source include/have_debug_sync.inc

--source include/count_sessions.inc

--echo #
--echo # Bug 1581949 (Querying GLOBAL_TEMPORARY_TABLES crashes if temp-table owning threads execute new queries)
--echo #

connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
--echo # connection con2

SET DEBUG_SYNC="dispatch_create_table_command_before_thd_root_free SIGNAL con2_ready WAIT_FOR thd_root_free";

send CREATE TEMPORARY TABLE t1 (a VARCHAR(256)) ENGINE=MyISAM;

connection default;
--echo # connection default

SET DEBUG_SYNC="now WAIT_FOR con2_ready";
SET DEBUG_SYNC="start_handler_ha_open_cloned SIGNAL con_default_ready WAIT_FOR finish";

send SELECT TABLE_SCHEMA, TABLE_NAME, ENGINE, TABLE_ROWS FROM INFORMATION_SCHEMA.GLOBAL_TEMPORARY_TABLES;

connection con1;
--echo # connection con1

SET DEBUG_SYNC="now WAIT_FOR con_default_ready";
SET DEBUG_SYNC="now SIGNAL thd_root_free";
disconnect con1;

connection con2;
--echo # connection con2

reap;

SET DEBUG_SYNC="now SIGNAL finish";

connection default;
--echo # connection default

reap;

disconnect con2;

--echo #
--echo # Bug 1614849 (INFORMATION_SCHEMA.TABLES (or other schema info table) and GLOBAL_TEMPORARY_TABLES queries running in parallel may crash or hang)
--echo #
connect (con1,localhost,root,,);
--echo # connection con1

SET DEBUG_SYNC="before_open_in_get_all_tables SIGNAL tables_query_ready WAIT_FOR tables_query_finish";
send SELECT * FROM INFORMATION_SCHEMA.TABLES;

connect (con2,localhost,root,,);
--echo # connection con2

SET DEBUG_SYNC="now WAIT_FOR tables_query_ready";
SET DEBUG_SYNC="fill_global_temporary_tables_thd_item_at_tables_debug_sync SIGNAL temp_tables_query_ready WAIT_FOR temp_tables_query_finish";
send SELECT * FROM INFORMATION_SCHEMA.GLOBAL_TEMPORARY_TABLES;

connection default;
--echo # connection default

SET DEBUG_SYNC="now WAIT_FOR temp_tables_query_ready";
SET DEBUG_SYNC="now SIGNAL tables_query_finish";

connection con1;
--echo # connection con1
--disable_result_log
reap;
--enable_result_log

disconnect con1;
connection default;
--echo # connection default

SET DEBUG_SYNC="now SIGNAL temp_tables_query_finish";

connection con2;
--echo # connection con2
reap;
disconnect con2;

connection default;
--echo # connection default
SET DEBUG_SYNC="reset";

--source include/wait_until_count_sessions.inc
