#
# Test the operation of evs.suspect_timeout.
#
# We set evs.inactive_timeout to a very high value so that evs.suspect_timeout can kick in instead.
#

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

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

# Save original auto_increment_offset values.
--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_1
--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'
--source include/wait_condition.inc

--let $wsrep_provider_options_node1 = `SELECT @@wsrep_provider_options`
SET GLOBAL wsrep_provider_options = 'evs.inactive_timeout=PT100M; evs.suspect_timeout=PT1S';

--connection node_2
--let $wsrep_provider_options_node2 = `SELECT @@wsrep_provider_options`
SET GLOBAL wsrep_provider_options = 'evs.inactive_timeout=PT100M; evs.suspect_timeout=PT1S';

--connection node_3
--let $wsrep_cluster_address_node3 = `SELECT @@wsrep_cluster_address`
--let $wsrep_provider_options_node3 = `SELECT @@wsrep_provider_options`

# Suspend node #3
--connection node_3
--source include/galera_suspend.inc

# Confirm that the other nodes have booted it out

--connection node_1
SET SESSION wsrep_sync_wait=0;
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'
--source include/wait_condition.inc

--connection node_2
SET SESSION wsrep_sync_wait=0;
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'
--source include/wait_condition.inc

--connection node_1
--disable_query_log
--eval SET GLOBAL wsrep_provider_options = '$wsrep_provider_options_node1';
--enable_query_log
--source include/wait_until_connected_again.inc

CREATE TABLE t1 (f1 INTEGER) engine=InnoDB;
INSERT INTO t1 VALUES (1);

--connection node_2
--disable_query_log
--eval SET GLOBAL wsrep_provider_options = '$wsrep_provider_options_node2';
--enable_query_log
--source include/wait_until_connected_again.inc

SET SESSION wsrep_sync_wait = 15;
SELECT COUNT(*) FROM t1;

# Reconnect node #3 so that MTR's end-of-test checks can run

--connection node_3
--source include/galera_resume.inc
--source include/wait_until_connected_again.inc

--disable_query_log
--eval SET GLOBAL wsrep_provider_options = '$wsrep_provider_options_node3';
--eval SET GLOBAL wsrep_cluster_address = '$wsrep_cluster_address_node3';
--enable_query_log
--source include/galera_wait_ready.inc

CALL mtr.add_suppression("WSREP: gcs_caused");
CALL mtr.add_suppression("WSREP: gcs/src/gcs_core\\.cpp:core_handle_uuid_msg");

SET SESSION wsrep_sync_wait = 15;
SELECT COUNT(*) FROM t1;

--connection node_1
--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'
--source include/wait_condition.inc

--connection node_2
--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'
--source include/wait_condition.inc

DROP TABLE t1;

# Restore original auto_increment_offset values.
--source ../galera/include/auto_increment_offset_restore.inc
