generic/131: wait until the server is ready or timeout
authorHou Tao <houtao1@huawei.com>
Fri, 4 Jan 2019 08:19:26 +0000 (16:19 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 6 Jan 2019 14:40:40 +0000 (22:40 +0800)
When running xfstests under KVM VM and the load of host is high,
only delaying 1s and checking the readiness of server are not
enough, and the test case will fail early.

Fix it by repeatedly checking the readiness signal until it's found,
or timeout is triggered.

[Eryu: check if lock server died or not, like v1 patch did]

Signed-off-by: Hou Tao <houtao1@huawei.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/generic/131

index d7c146aeafab3df1f901f8a543e1732f96b17204..c7bac3bcf705febf7450d33bfc088fa23525528c 100755 (executable)
@@ -37,10 +37,25 @@ TESTFILE=$TEST_DIR/lock_file
 src/locktest $TESTFILE 2>&1 > $TEST_DIR/server.out &
 locktest_pid1=$!
 
-sleep 1
+timeout=30
+while [ $timeout -gt 0 ]; do
+       sleep 1
 
-PORT=$(cat $TEST_DIR/server.out | grep "^server port: " | awk '{print $3}')
-if [ -z $PORT ]; then
+       PORT=$(cat $TEST_DIR/server.out | grep "^server port: " | awk '{print $3}')
+       if [ -n "$PORT" ]; then
+               break
+       fi
+
+       # check the existence of server process
+       if ! kill -s 0 $locktest_pid1 >/dev/null 2>&1; then
+               echo "Server died abnormally"
+               exit 1
+       fi
+
+       let timeout=timeout-1
+done
+
+if [ -z "$PORT" ]; then
        echo "Could not get server port"
        exit 1
 fi