1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-21 23:18:00 -08:00

Replace poor man's synchronization primitive (i.e. sleep) with a wait

until construct in the hopes of making these tests less flaky.
This commit is contained in:
anton 2024-12-21 07:49:03 +00:00
parent 7ed182d8b9
commit d6933ec7e0
2 changed files with 17 additions and 3 deletions

View File

@ -1,9 +1,11 @@
#!/bin/sh
#
# $OpenBSD: follow-overwrite-data.sh,v 1.2 2012/11/03 08:41:25 ajacoutot Exp $
# $OpenBSD: follow-overwrite-data.sh,v 1.3 2024/12/21 07:49:03 anton Exp $
# test if tail follows a file overwritten by data
. "$(dirname "${0}")/util.sh"
#set TMPDIR to a nfs-based dir for nfs testing
DIR=$(mktemp -d)
echo DIR=${DIR}
@ -30,8 +32,7 @@ echo 'baar' > ${DIR}/bar
# smaller data without delay
echo 'bar' > ${DIR}/bar
# hey nfs !
sleep 5
wait_until "[ `grep -c bar ${OUT}` = 2 ]"
kill ${PID}
diff -u ${OUT} ${0%%.sh}.out || exit 1
[ $(grep -c "tail: ${DIR}/bar has been truncated, resetting." ${ERR}) -eq 3 ] || exit 2

View File

@ -0,0 +1,13 @@
# $OpenBSD: util.sh,v 1.1 2024/12/21 07:49:03 anton Exp $
wait_until() {
local _i=0
while [ "$_i" -lt 8 ]; do
sh -x -c "$*" && return 0
sleep 0.5
_i="$((_i + 1))"
done
echo timeout
return 1
}