# ==== Purpose ====
#
# Verify that a slave without replication privileges has
# Slave_IO_Running = No
#
# ==== Method ====
#
# We do the following steps:
# - Create a new replication user on master
# - Connect to slave and start replication as this user.
# - Verify that slave can replicate well, by creating a table and
#   inserting a row into it.
# - Delete the user from the master.
# - Stop and start the slave (this should fail).
# - Check the Slave_IO_Running column of SHOW SLAVE STATUS.
#
# ==== Related bugs ====
#
# BUG#10780: slave can't connect to master - IO and SQL threads running

--source include/master-slave.inc

--echo ==== Create new replication user ====
--echo [on master]
connection master;
grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl';
flush privileges;
--echo [on slave]
sync_slave_with_master;
source include/stop_slave.inc;
change master to master_user='rpl',master_password='rpl';
source include/start_slave.inc;

--echo ==== Do replication as new user ====
--echo [on master]
connection master;
create table t1 (n int);
insert into t1 values (1);
--echo [on slave]
sync_slave_with_master;
select * from t1;

--echo ==== Delete new replication user ====
--echo [on master]
connection master;
drop user rpl@127.0.0.1;
flush privileges;

--echo [on slave]
sync_slave_with_master;

--echo ==== Restart slave without privileges =====
# (slave.err will contain access denied error for this START SLAVE command)
source include/stop_slave.inc;
start slave;
source include/wait_for_slave_sql_to_start.inc;
source include/wait_for_slave_io_to_stop.inc;

--echo ==== Verify that Slave_IO_Running = No ====
let $result= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, 1);
--echo Slave_IO_Running = $result (should be No)

--echo ==== Cleanup (Note that slave IO thread is not running) ====
drop table t1;
# cleanup: slave io thread has been stopped "irrecoverably"
# so we clean up mess manually

--echo [on master]
connection master;
drop table t1;
