esac
}
-# Continually retry a function requiring a sufficient delay to _pass_
+# Retry a function requiring a sufficient delay to _pass_
+# using a truncated exponential backoff method.
# Example: retry_delay dd_reblock_1 .1 6
# This example will call the dd_reblock_1 function with
# an initial delay of .1 second and call it at most 6 times
. $srcdir/test-lib.sh
-
+# We use --local here so as to not activate
+# potentially very many remote mounts.
mount_points=$(df --local -P 2>&1 | sed -n 's,.*[0-9]% \(/.\),\1,p')
test -z "$mount_points" && skip_test_ "this test requires a non-root mount point"
eval "ls -i $opts $parent_dir" | sed 's/ .*//'
}
-# FIXME: use a timeout, in case stat'ing mount points takes too long.
-
for dir in $mount_points; do
readdir_inode=$(inode_via_readdir $dir)
test $? = 77 && continue
- stat_inode=$(env stat --format=%i $dir)
+ stat_inode=$(timeout 1 stat --format=%i $dir)
# If stat fails or says the inode is 0, skip $dir.
case $stat_inode in 0|'') continue;; esac
test "$readdir_inode" = "$stat_inode" || fail=1
|| skip_test_ '/dev/stdin is not readable'
mv f g < /dev/stdin > out 2>&1 & pid=$!
-sleep 1
-kill $pid
-# Make sure out contains the prompt.
-case "`cat out`" in
- "mv: try to overwrite \`g', overriding mode 0000"*) ;;
- *) fail=1 ;;
-esac
+# Wait up to 3.1s for the expected prompt
+check_overwrite_prompt()
+{
+ local delay="$1"
+ case "`cat out`" in
+ "mv: try to overwrite \`g', overriding mode 0000"*) ;;
+ *) sleep $delay; return 1;;
+ esac
+}
+retry_delay_ check_overwrite_prompt .1 5 || fail=1
+
+kill $pid
mv -f h i > out 2>&1 || fail=1
test -f i || fail=1
pid=$!
# The buggy rm (fileutils-4.1.9) would hang here, waiting for input.
-# Give the working rm a chance to remove the file.
-sleep 1
-
-# The file must no longer exist.
-ls -l dangle > /dev/null 2>&1 && fail=1
-ls -l symlink > /dev/null 2>&1 && fail=1
+# Wait up to 3.1s for rm to remove the files
+check_files_removed() {
+ local delay="$1"
+ local present=0
+ ls -l dangle > /dev/null 2>&1 && present=1
+ ls -l symlink > /dev/null 2>&1 && present=1
+ test $present = 1 && { sleep $delay; return 1; } || :
+}
+retry_delay_ check_files_removed .1 5 || fail=1
kill $pid > /dev/null 2>&1