Make background test processes wait for their subsequent foreground PV to start, to make a race condition less likely to trigger test failures on slower systems.

This commit is contained in:
Andrew Wood
2024-12-15 13:36:14 +00:00
parent 7d18083dda
commit 4f58a3d751
5 changed files with 32 additions and 10 deletions
@@ -18,14 +18,17 @@ if ! "${testSubject}" -h 2>/dev/null | grep -Eq "^ -R,"; then
exit 77
fi
# Generate some data.
# Generate 10MiB of data.
dd if=/dev/urandom of="${workFile1}" bs=1024 count=10240 2>/dev/null
# Run a few remote control commands in the background.
#
echo FAIL > "${workFile3}"
true > "${workFile4}"
(
set +e
# Don't start doing anything until the main transfer process, started below, has begun.
while ! test -s "${workFile4}"; do sleep 0.1; done
sleep 2
for loopCount in 1 2 3; do
"${testSubject}" -R "$(cat "${workFile4}")" -apterb || exit 1
+7 -3
View File
@@ -24,6 +24,7 @@ fi
# Skip the test if "-d" does not work.
sleep 2 &
pid=$!
sleep 0.1
"${testSubject}" -d "${pid}" -f -i 0.5 >/dev/null 2>"${workFile1}"
if grep -Fq ' -d: not available' "${workFile1}"; then
@@ -34,17 +35,20 @@ fi
# Check "--watchfd PID:FD".
# See the "Watchfd" tests for more detail.
seq 1 100 > "${workFile1}"
true > "${workFile3}"
# shellcheck disable=SC2030
(sleep 1; read -r line; sleep 1; read -r line; sleep 1) <"${workFile1}" &
(while ! test -s "${workFile3}"; do sleep 0.1; done; sleep 1; read -r line; sleep 1; read -r line; sleep 1) <"${workFile1}" &
pid=$!
sleep 0.1
{ runWithValgrind -d "${pid}:0" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1
{ runWithValgrind -P "${workFile3}" -d "${pid}:0" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1
# Check "--watchfd PID".
seq 1 100 > "${workFile1}"
seq 1 300 > "${workFile2}"
true > "${workFile3}"
# shellcheck disable=SC2030
(
while ! test -s "${workFile3}"; do sleep 0.1; done
sleep 1
read -r line
exec 9<"${workFile2}"
@@ -59,6 +63,6 @@ sleep 1
) <"${workFile1}" &
pid=$!
sleep 0.1
{ runWithValgrind -d "${pid}" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1
{ runWithValgrind -P "${workFile3}" -d "${pid}" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1
exit 0
+4 -1
View File
@@ -17,10 +17,13 @@ if ! "${testSubject}" -h 2>/dev/null | grep -Eq "^ -R,"; then
exit 77
fi
# Generate an empty test file.
# Generate a 10MiB test file of null bytes.
dd if=/dev/zero of="${workFile1}" bs=1024 count=10240 2>/dev/null
true > "${workFile4}"
(
# Don't start doing anything until the main transfer process, started below, has begun.
while ! test -s "${workFile4}"; do sleep 0.1; done
sleep 1
"${testSubject}" -R "$(cat "${workFile4}")" -a
sleep 2
+8 -3
View File
@@ -9,6 +9,7 @@ true "${testSubject:?not set - call this from 'make check'}"
true "${workFile1:?not set - call this from 'make check'}"
true "${workFile2:?not set - call this from 'make check'}"
true "${workFile3:?not set - call this from 'make check'}"
true "${workFile4:?not set - call this from 'make check'}"
# Skip the test if "-d" is not available.
if ! "${testSubject}" -h | grep -Fq ' -d'; then
@@ -21,8 +22,12 @@ seq 1 300 > "${workFile2}"
# Run a background process to perform a few reads from a file, opening a
# second file after a moment.
# We only start doing anything once the PV process below has started (the
# workFile3 check).
# NB we just export line to make shellcheck think it's used.
true > "${workFile3}"
(
while ! test -s "${workFile3}"; do sleep 0.1; done
export line
sleep 1
read -r line
@@ -34,17 +39,17 @@ sleep 1
pid=$!
sleep 0.1
"${testSubject}" -d "${pid}" -f -i 0.5 >/dev/null 2>"${workFile3}"
"${testSubject}" -P "${workFile3}" -d "${pid}" -f -i 0.5 >/dev/null 2>"${workFile4}"
# Skip the test if "-d" does not work.
if grep -Fq ' -d: not available' "${workFile3}"; then
if grep -Fq ' -d: not available' "${workFile4}"; then
echo "no \`--watchfd' / \`-d' option on this platform"
exit 77
fi
# Process the output to make it easier to handle.
# NB "ESC [ A" is "cursor up", we turn that into "-" and a newline.
tr '\r' '\n' < "${workFile3}" | sed 's/.\[A/-!/g' | tr '!' '\n' > "${workFile1}"
tr '\r' '\n' < "${workFile4}" | sed 's/.\[A/-!/g' | tr '!' '\n' > "${workFile1}"
# We should see at least 2 file positions for fd 0.
positionsReported="$(awk '/^ *0:/ {print $2}' < "${workFile1}" | sort -n | uniq)"
+9 -2
View File
@@ -8,6 +8,7 @@ test "${SKIP_ALL_TESTS}" = "1" && exit 77
true "${testSubject:?not set - call this from 'make check'}"
true "${workFile1:?not set - call this from 'make check'}"
true "${workFile2:?not set - call this from 'make check'}"
true "${workFile3:?not set - call this from 'make check'}"
# Skip the test if "-d" is not available.
if ! "${testSubject}" -h | grep -Fq ' -d'; then
@@ -18,12 +19,18 @@ fi
seq 1 100 > "${workFile1}"
# Run a background process to perform a few reads from a file.
# We only start doing anything once the PV process below has started (the
# workFile3 check).
# NB we just export line to make shellcheck think it's used.
(export line; sleep 1; read -r line; sleep 1; read -r line; sleep 1) <"${workFile1}" &
true > "${workFile3}"
(
while ! test -s "${workFile3}"; do sleep 0.1; done
export line; sleep 1; read -r line; sleep 1; read -r line; sleep 1
) <"${workFile1}" &
pid=$!
sleep 0.1
"${testSubject}" -d "${pid}:0" -f -i 0.5 >/dev/null 2>"${workFile2}"
"${testSubject}" -P "${workFile3}" -d "${pid}:0" -f -i 0.5 >/dev/null 2>"${workFile2}"
# Skip the test if "-d" does not work.
if grep -Fq ' -d: not available' "${workFile2}"; then