From ddd0d41173eeb500a4a16495fefe5568782252cf Mon Sep 17 00:00:00 2001
From: grev <grev>
Date: Thu, 20 Sep 2007 03:02:48 +0000
Subject: [PATCH] b=13499 i=Adilger

Wait recovery complete before AFTERUSED is checked.
---
 lustre/tests/replay-single.sh  |  2 +-
 lustre/tests/test-framework.sh | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lustre/tests/replay-single.sh b/lustre/tests/replay-single.sh
index aa05069b37..45c86e6412 100755
--- a/lustre/tests/replay-single.sh
+++ b/lustre/tests/replay-single.sh
@@ -474,7 +474,7 @@ test_20b() { # bug 10480
 
     fail $SINGLEMDS                            # start orphan recovery
     df -P $DIR || df -P $DIR || true    # reconnect
-    sleep 2
+    wait_mds_recovery_done || error "MDS recovery not done"
 
     AFTERUSED=`df -P $DIR | tail -1 | awk '{ print $3 }'`
     log "before $BEFOREUSED, after $AFTERUSED"
diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh
index a77b2317ba..df2293684d 100644
--- a/lustre/tests/test-framework.sh
+++ b/lustre/tests/test-framework.sh
@@ -487,6 +487,24 @@ wait_for() {
     wait_for_host $HOST
 }
 
+wait_mds_recovery_done () {
+    local timeout=`do_facet mds cat /proc/sys/lustre/timeout`
+#define OBD_RECOVERY_TIMEOUT (obd_timeout * 5 / 2)
+# as we are in process of changing obd_timeout in different ways
+# let's set MAX longer than that
+    MAX=$(( timeout * 4 ))
+    WAIT=0
+    while [ $WAIT -lt $MAX ]; do
+        STATUS=`do_facet mds grep status /proc/fs/lustre/mdt/*-MDT*/recovery_status`
+        echo $STATUS | grep COMPLETE && return 0
+        sleep 5
+        WAIT=$((WAIT + 5))
+        echo "Waiting $(($MAX - $WAIT)) secs for MDS recovery done"
+    done
+    echo "MDS recovery not done in $MAX sec"
+    return 1            
+}
+
 client_df() {
     # not every config has many clients
     if [ ! -z "$CLIENTS" ]; then
-- 
GitLab