--source include/have_debug.inc
# Valgrind does not work well with test that crashes the server
--source include/not_valgrind.inc

# Same as spider/bugfix.mdev_27438, but actually using a spider table.
install soname 'ha_spider';
set spider_same_server_link= 1;
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');

CREATE TABLE t1 (a INT);
create table t2 (a int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t1"';
INSERT INTO t2 VALUES (1);

# crash the server.
--let $expect_file_name= `select regexp_replace(@@tmpdir, '^.*/','')`
--let $expect_file_name= $MYSQLTEST_VARDIR/tmp/$expect_file_name.expect
--exec echo wait > $expect_file_name
SET SESSION debug_dbug="+d,crash_commit_after_log";
--error 2006,2013,2026
INSERT INTO t2 VALUES (2);

# restart the server
--exec echo restart >> $expect_file_name
--enable_reconnect
--source include/wait_until_connected_again.inc

call mtr.add_suppression(".*\\[ERROR\\] mariadbd: Table './test/t1' is marked as crashed and should be repaired");
call mtr.add_suppression(".*\\[Warning\\] Checking table:   './test/t1'");
set spider_same_server_link= 1;
--disable_ps_protocol
select * from t2;
--enable_ps_protocol
drop server srv;
drop table t1, t2;
--disable_query_log
--source ../../include/clean_up_spider.inc
