# MDEV-25674: Test the `Master_Retry_Count` field of
# `CHANGE MASTER [name] TO` and `SHOW SLAVE [name] STATUS` & co..
# feature testing is in `multi_source.connects_tried` and
# `--master-retry-count` testing is in `main.change_master_default`.
# The use of two connections tests that the field is now per-connection.
--source include/have_perfschema.inc

--echo # Replace `--master-retry-count` when specified
CHANGE MASTER 'named' TO master_retry_count=11, master_host='example.com';
# Default master does not replace named master
CHANGE MASTER TO master_retry_count=10,
  master_host='127.0.0.1', master_ssl_verify_server_cert=0; # check-testcase
SELECT Connection_name, Master_Retry_Count
  FROM information_schema.SLAVE_STATUS;

--echo # Conventional views also show the configurations
--let $all_slaves_status= 1
--let $status_items= Connection_name, Master_Retry_Count
--source include/show_slave_status.inc
--let $all_slaves_status= 0
--let $status_items= Master_Retry_Count
--source include/show_slave_status.inc
--let $slave_name= 'named'
--source include/show_slave_status.inc
SELECT CHANNEL_NAME, CONNECTION_RETRY_COUNT
  FROM performance_schema.replication_connection_configuration;

--echo # Restore specified config on restart
--let $restart_parameters= --skip-slave-start
--source include/restart_mysqld.inc # not_embedded
SELECT Connection_name, Master_Retry_Count
  FROM information_schema.SLAVE_STATUS;

--echo # Keep specified config on RESET REPLICA
RESET REPLICA 'named';
RESET REPLICA;
SELECT Connection_name, Master_Retry_Count
  FROM information_schema.SLAVE_STATUS;

--echo # Don't replace when not specified
CHANGE MASTER TO master_user='root';
CHANGE MASTER 'named' TO master_user='root';
SELECT Connection_name, Master_Retry_Count
  FROM information_schema.SLAVE_STATUS;

--echo # 0 does not mean "not specified"
CHANGE MASTER TO master_retry_count=0;
CHANGE MASTER 'named' TO master_retry_count=0;
SELECT Connection_name, Master_Retry_Count
  FROM information_schema.SLAVE_STATUS;

--echo # Truncates decimals
CHANGE MASTER TO master_retry_count=10.75;
CHANGE MASTER 'named' TO master_retry_count=11.25;
SELECT Connection_name, Master_Retry_Count
  FROM information_schema.SLAVE_STATUS;

--echo # Caps values (such as UINT64_MAX + 1) to `--master-retry-count`'s max
CHANGE MASTER TO master_retry_count=18446744073709551616;
CHANGE MASTER 'named' TO master_retry_count=18446744073709551616;
SELECT Connection_name, Master_Retry_Count
  FROM information_schema.SLAVE_STATUS;

--echo # Negative
--error ER_PARSE_ERROR
CHANGE MASTER TO master_retry_count=-1;
--error ER_PARSE_ERROR
CHANGE MASTER 'named' TO master_retry_count=-1;
--echo # NaN
--error ER_PARSE_ERROR
CHANGE MASTER TO master_retry_count='5';
--error ER_PARSE_ERROR
CHANGE MASTER 'named' TO master_retry_count='5';

--echo # Cleanup
RESET REPLICA 'named' ALL;
