################################################################################
# WL#6969    Additional concurrency tests for BGC
#
# Concurrency test verifies that there is not 3-way deadlock any more.
#
# ################################################################################
--source include/have_debug_sync.inc
--source include/master-slave.inc
--source include/install_semisync.inc

SET @debug_save= @@GLOBAL.DEBUG;
SET GLOBAL rpl_semi_sync_master_timeout= 600000;

--disable_query_log
--disable_result_log
--let $n= 11
--let $i= 1
while ($i < $n)
{
  --eval CREATE TABLE t$i(c1 INT) ENGINE= InnoDB;
  --inc $i
}
--enable_result_log
--enable_query_log

--source include/sync_slave_sql_with_master.inc

--connection master
SET GLOBAL debug= 'd,semi_sync_3-way_deadlock';
SET DEBUG_SYNC= "before_process_commit_stage_queue WAIT_FOR signal.rotate_finished no_clear_event";

--echo # Build 10 connections to master server
--disable_query_log
--disable_result_log
--let $i= 1
while ($i < $n)
{
  --connect(con$i,127.0.0.1,root,,test,$MASTER_MYPORT,)
  --inc $i
}
--enable_result_log
--enable_query_log

--echo # Execute INSERT statement on these 10 connections in parallel
--disable_query_log
--disable_result_log

--let $i= 1
while ($i < $n)
{
  --connection con$i
  --send
  --eval INSERT INTO t$i VALUES(2)
  --inc $i
}
--enable_result_log
--enable_query_log

--connection master1
SET DEBUG_SYNC= "before_rotate_binlog SIGNAL signal.rotate_finished";
--real_sleep 3
--echo # Rotate binlog file
FLUSH LOGS;

--disable_query_log
--disable_result_log
--let $i= 1
while ($i < $n)
{
  --connection con$i
  --reap
  --inc $i
}
--enable_result_log
--enable_query_log

# clean up
--connection master
--disable_query_log
--disable_result_log
# disconnect connections
--let $i= 1
while ($i < $n)
{
  --disconnect con$i
  --inc $i
}
# drop tables
--let $i= 1
while ($i < $n)
{
  --eval DROP TABLE t$i
  --inc $i
}
--enable_result_log
--enable_query_log
SET DEBUG_SYNC= 'RESET';
SET @@GLOBAL.DEBUG= @debug_save;
--source include/sync_slave_sql_with_master.inc

--source include/uninstall_semisync.inc
--source include/rpl_end.inc
