#
# Construct a situation where Donor node partitions in the
# middle of SST. The Donor should stay in non-Primary state instead of
# crashing in assertion in wsrep-lib.
#
# In the test, node_2 is restarted and node_1 configured to be
# the donor. Node_1 execution is stopped before sst_sent() is
# called and node_1 is made to partition from the cluster.
#

--source include/galera_cluster.inc
--source include/have_innodb.inc
--source include/have_debug_sync.inc
--source include/big_test.inc

--let $galera_connection_name = node_3
--let $galera_server_number = 3
--source include/galera_connect.inc

--let $node_1=node_1
--let $node_2=node_2
--let $node_3=node_3
--source ../galera/include/auto_increment_offset_save.inc

--connection node_2
--source include/shutdown_mysqld.inc
--remove_file $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat

--connection node_1
SET GLOBAL debug_dbug = '+d,sync.wsrep_sst_donor_after_donation';

--connection node_2
--source include/start_mysqld.inc

--connection node_1
SET DEBUG_SYNC = 'now WAIT_FOR sync.wsrep_sst_donor_after_donation_reached';
SET GLOBAL wsrep_provider_options = 'gmcast.isolate=1';
SET SESSION wsrep_sync_wait=0;
--let $wait_condition = SELECT VARIABLE_VALUE = 'non-Primary' FROM information_schema.global_status WHERE VARIABLE_NAME = 'wsrep_cluster_status'
--source include/wait_condition.inc

SET DEBUG_SYNC = 'now SIGNAL signal.wsrep_sst_donor_after_donation_continue';
SET DEBUG_SYNC = 'RESET';
SET GLOBAL debug_dbug = '';

SET GLOBAL wsrep_provider_options = 'gmcast.isolate=0';
SET SESSION wsrep_sync_wait=15;

--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM information_schema.global_status WHERE VARIABLE_NAME = 'wsrep_cluster_size'
--connection node_1
--source include/wait_condition.inc
--connection node_2
--source include/wait_condition.inc
--connection node_3

--connection node_1
--let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM information_schema.global_status WHERE VARIABLE_NAME = 'wsrep_ready'
--source include/wait_condition.inc

--source ../galera/include/auto_increment_offset_restore.inc

--connection node_1
CALL mtr.add_suppression("WSREP: sst sent called when not SST donor, state CONNECTED");
CALL mtr.add_suppression("WSREP: .* returned an error: Not connected to Primary Component");
