From 9553427619f59db54b4d7a2e35204693b01f9335 Mon Sep 17 00:00:00 2001
From: Chaoguang Lin <chaoguang.lin@snowflake.com>
Date: Fri, 13 Aug 2021 11:36:49 -0700
Subject: [PATCH] try to fix exlcude fdbcli test

---
 bindings/python/tests/fdbcli_tests.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/bindings/python/tests/fdbcli_tests.py b/bindings/python/tests/fdbcli_tests.py
index 17a94e16b1..55325a0c16 100755
--- a/bindings/python/tests/fdbcli_tests.py
+++ b/bindings/python/tests/fdbcli_tests.py
@@ -341,7 +341,7 @@ def get_fdb_process_addresses(logger):
     assert len(addresses) == process_number
     return addresses
 
-@enable_logging()
+@enable_logging(logging.DEBUG)
 def coordinators(logger):
     # we should only have one coordinator for now
     output1 = run_fdbcli_command('coordinators')
@@ -366,8 +366,9 @@ def coordinators(logger):
     # auto change should go back to 1 coordinator
     run_fdbcli_command('coordinators', 'auto')
     assert len(get_value_from_status_json(True, 'client', 'coordinators', 'coordinators')) == 1
+    wait_for_database_available(logger)
 
-@enable_logging()
+@enable_logging(logging.DEBUG)
 def exclude(logger):
     # get all processes' network addresses
     addresses = get_fdb_process_addresses(logger)
@@ -413,6 +414,7 @@ def exclude(logger):
     # check the include is successful
     output4 = run_fdbcli_command('exclude')
     assert no_excluded_process_output in output4
+    wait_for_database_available(logger)
 
 # read the system key 'k', need to enable the option first
 def read_system_key(k):
@@ -440,6 +442,13 @@ def throttle(logger):
     assert enable_flag == "`0'"
     # TODO : test manual throttling, not easy to do now
 
+def wait_for_database_available(logger):
+    # sometimes the change takes some time to have effect and the database can be unavailable at that time
+    # this is to wait until the database is available again
+    while not get_value_from_status_json(True, 'client', 'database_status', 'available'):
+        time.sleep(1)
+        logger.debug("Database unavailable for now, wait for one second")
+
 if __name__ == '__main__':
     # fdbcli_tests.py <path_to_fdbcli_binary> <path_to_fdb_cluster_file> <process_number>
     assert len(sys.argv) == 4, "Please pass arguments: <path_to_fdbcli_binary> <path_to_fdb_cluster_file> <process_number>"