From 91245909a2f0c89444ecb5af587284f53b7196ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= <jan.lindstrom@mariadb.com>
Date: Wed, 11 Apr 2018 14:06:29 +0300
Subject: [PATCH] MDEV-12903: encryption.innodb_encryption_discard_import fails
 in buildbot with FOUND vs NOT FOUND

Wait until rotation has ended and shutdown before grep to make sure
that dirty pages are on datafiles.
---
 .../t/innodb_encryption_discard_import.test   | 22 ++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test b/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test
index 3e78d468ab1..099d16f6927 100644
--- a/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test
+++ b/mysql-test/suite/encryption/t/innodb_encryption_discard_import.test
@@ -37,10 +37,12 @@ set autocommit=1;
 
 --echo # Wait max 10 min for key encryption threads to encrypt all spaces
 --let $wait_timeout= 600
---let $wait_condition=SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0
+--let $wait_condition=SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND ROTATING_OR_FLUSHING <> 0
 --source include/wait_condition.inc
 
---sleep 5
+# shutdown so that grep is safe
+--source include/shutdown_mysqld.inc
+
 --echo # tablespaces should be now encrypted
 --let SEARCH_PATTERN=foobar
 --echo # t1 yes on expecting NOT FOUND
@@ -55,6 +57,8 @@ set autocommit=1;
 -- let SEARCH_FILE=$t3_IBD
 -- source include/search_pattern_in_file.inc
 
+--source include/start_mysqld.inc
+
 --list_files $MYSQLD_DATADIR/test
 FLUSH TABLES t1, t2, t3 FOR EXPORT;
 perl;
@@ -81,7 +85,9 @@ SELECT COUNT(1) FROM t2;
 ALTER TABLE t3 IMPORT TABLESPACE;
 SELECT COUNT(1) FROM t3;
 
---sleep 5
+# shutdown so that grep is safe
+--source include/shutdown_mysqld.inc
+
 --echo # tablespaces should remain encrypted after import
 --let SEARCH_PATTERN=foobar
 --echo # t1 yes on expecting NOT FOUND
@@ -96,6 +102,8 @@ SELECT COUNT(1) FROM t3;
 -- let SEARCH_FILE=$t3_IBD
 -- source include/search_pattern_in_file.inc
 
+--source include/start_mysqld.inc
+
 ALTER TABLE t1 ENGINE InnoDB;
 SHOW CREATE TABLE t1;
 ALTER TABLE t2 ENGINE InnoDB;
@@ -112,7 +120,9 @@ SELECT COUNT(1) FROM t1;
 SELECT COUNT(1) FROM t2;
 SELECT COUNT(1) FROM t3;
 
---sleep 5
+# shutdown so that grep is safe
+--source include/shutdown_mysqld.inc
+
 --echo # Tablespaces should be encrypted after restart
 --let SEARCH_PATTERN=foobar
 --echo # t1 yes on expecting NOT FOUND
@@ -127,9 +137,11 @@ SELECT COUNT(1) FROM t3;
 -- let SEARCH_FILE=$t3_IBD
 -- source include/search_pattern_in_file.inc
 
+--source include/start_mysqld.inc
+
 --echo # Wait max 10 min for key encryption threads to encrypt all spaces
 --let $wait_timeout= 600
---let $wait_condition=SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0
+--let $wait_condition=SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.INNODB_TABLESPACES_ENCRYPTION WHERE MIN_KEY_VERSION = 0 AND ROTATING_OR_FLUSHING <> 0
 --source include/wait_condition.inc
 
 --echo # Success!
-- 
2.30.9