# Not supported in embedded
--source include/not_embedded.inc

# This test case needs InnoDB.
-- source include/have_innodb.inc

call mtr.add_suppression('InnoDB: Failed to find tablespace for table \'".*".".*"\' in the cache');
call mtr.add_suppression('InnoDB: Allocated tablespace [0-9]+, old maximum was [0-9]+');

create table t1(f1 int not null, f2 int not null, index idx(f2))engine=innodb;
insert into t1 values(1, 2);

SET GLOBAL innodb_fast_shutdown = 0;

# Restart the server in force recovery mode
--echo # Stop server

# Write file to make mysql-test-run.pl wait for the server to stop
-- exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

# Request shutdown
-- send_shutdown

# Call script that will poll the server waiting for it to disapear
-- source include/wait_until_disconnected.inc

--echo # Restart server.

# Write file to make mysql-test-run.pl start up the server again, ensure
# that no background threads are started, so that we can check that it
# shuts down properly.
--exec echo "restart:--innodb-force-recovery=4" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

# Turn on reconnect
--enable_reconnect

# Call script that will poll the server waiting for it to be back online again
--source include/wait_until_connected_again.inc

# Turn off reconnect again
--disable_reconnect

select * from t1;

--error ER_OPEN_AS_READONLY
insert into t1 values(2, 3);

--error ER_INNODB_READ_ONLY
alter table t1 add f3 int not null, algorithm=copy;

--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
alter table t1 add f3 int not null, algorithm=inplace;

--error ER_INNODB_READ_ONLY
drop index idx on t1;

--error ER_OPEN_AS_READONLY
update t1 set f1=3 where f2=2;

--error ER_INNODB_READ_ONLY
create table t3(f1 int not null)engine=innodb;

--error ER_BAD_TABLE_ERROR
drop table t3;

--error ER_ERROR_ON_RENAME
rename table t1 to t3;

--error ER_OPEN_AS_READONLY
truncate table t1;

drop table t1;
show tables;
