Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/gold_tests/remap/remap_acl.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ def _configure_traffic_server(self) -> int:
#
tr = Test.AddTestRun("Await config reload")
p = tr.Processes.Default
p.Command = 'echo awaiting config reload'
p.Env = ts.Env
Test_remap_acl._ts_reload_counter += 1
count = Test_remap_acl._ts_reload_counter
await_config_reload = tr.Processes.Process(f'config_reload_succeeded_{count}', 'sleep 30')
await_config_reload.Ready = When.FileContains(ts.Disk.diags_log.Name, "remap.config finished loading", count)
p.StartBefore(await_config_reload)
count = 1 + Test_remap_acl._ts_reload_counter
condwait = os.path.join(Test.Variables.AtsTestToolsDir, 'condwait')
p.Command = (f"'{condwait}' 30 --contains '{ts.Disk.diags_log.Name}' "
f"'remap.config finished loading' {count}")
p.Env = ts.Env
tr.StillRunningAfter = ts

else:
record_config = {
Expand Down
12 changes: 6 additions & 6 deletions tests/gold_tests/remap_yaml/remap_acl_yaml.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ def _configure_traffic_server(self) -> int:
#
tr = Test.AddTestRun("Await config reload")
p = tr.Processes.Default
p.Command = 'echo awaiting config reload'
p.Env = ts.Env
Test_remap_acl._ts_reload_counter += 1
count = Test_remap_acl._ts_reload_counter
await_config_reload = tr.Processes.Process(f'config_reload_succeeded_{count}', 'sleep 30')
await_config_reload.Ready = When.FileContains(ts.Disk.diags_log.Name, "remap.yaml finished loading", count)
p.StartBefore(await_config_reload)
count = 1 + Test_remap_acl._ts_reload_counter
condwait = os.path.join(Test.Variables.AtsTestToolsDir, 'condwait')
p.Command = (f"'{condwait}' 30 --contains '{ts.Disk.diags_log.Name}' "
f"'remap.yaml finished loading' {count}")
p.Env = ts.Env
tr.StillRunningAfter = ts

else:
record_config = {
Expand Down
66 changes: 56 additions & 10 deletions tests/tools/condwait
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#
# CONDITION is the ('test' command) condition to wait for. (It may contain white space.)
# For file existence tests (-f, -e, -d), glob patterns are supported (e.g., -f /path/crash-*.log).
# Use "--contains FILE PATTERN COUNT" to wait until FILE contains PATTERN in at least COUNT lines.
#
# MAX-WAIT is the maximum number of seconds to wait for the condition. If it is omitted, it defaults to 60.
#
Expand All @@ -34,8 +35,13 @@
WAIT=60
POST_WAIT=0

usage() {
echo "usage: condwait [ MAX-WAIT [ POST-WAIT ] ] TEST-CONDITION" >&2
echo " condwait [ MAX-WAIT [ POST-WAIT ] ] --contains FILE PATTERN COUNT" >&2
}
Comment thread
bneradt marked this conversation as resolved.

if [[ "$1" = "" ]] ; then
echo "usage: condwait [ MAX-WAIT [ POST-WAIT ] ] TEST-CONDTION" >&2
usage
exit 1
fi

Expand All @@ -44,7 +50,7 @@ if [[ "$X" = "$1" ]] ; then
WAIT=$1
shift
if [[ "$1" = "" ]] ; then
echo "usage: condwait [ MAX-WAIT [ POST-WAIT ] ] TEST-CONDTION" >&2
usage
exit 1
fi
X=$( echo "$1" | sed 's/x/yy/g' | sed 's/[^0-9]/x/g' )
Expand All @@ -55,24 +61,64 @@ if [[ "$X" = "$1" ]] ; then
fi

if [[ "$1" = "" ]] ; then
echo "usage: condwait [ MAX-WAIT [ POST-WAIT ] ] TEST-CONDTION" >&2
usage
exit 1
fi

# Check if this is a simple file existence test (-f, -e, -d). If so, use ls -d
# which handles glob patterns properly. Otherwise, use test for the condition.
if [[ "$1" = "--contains" ]]; then
if [[ $# -ne 4 ]] || ! [[ "$4" =~ ^[0-9]+$ ]]; then
usage
exit 1
fi
fi

# Check simple file existence tests (-f, -e, -d) specially so literal paths with
# whitespace work while glob patterns remain supported.
check_condition() {
if [[ "$1" = "-f" || "$1" = "-e" || "$1" = "-d" ]] && [[ $# -eq 2 ]]; then
# Use ls -d for file existence tests to support glob patterns.
ls -d $2 >/dev/null 2>&1
if [[ "$1" = "--contains" ]]; then
[[ -f "$2" ]] || return 1
local matches
matches=$(awk -v pattern="$3" -v expected="$4" '
BEGIN {
if (expected == 0) {
print 0
found = 1
exit
}
}
index($0, pattern) {
count++
if (count >= expected) {
print count
found = 1
exit
}
}
END {
if (!found) {
print count + 0
}
}
' "$2")
(( matches >= $4 ))
Comment thread
bneradt marked this conversation as resolved.
Comment thread
bneradt marked this conversation as resolved.
elif [[ "$1" = "-f" || "$1" = "-e" || "$1" = "-d" ]] && [[ $# -eq 2 ]]; then
if [[ "$2" = *[\*\?\[]* ]]; then
# Use compgen for file existence tests to support glob patterns.
local match
while IFS= read -r match; do
test "$1" "$match" && return 0
done < <(compgen -G "$2")
return 1
fi
test "$1" "$2"
else
Comment thread
bneradt marked this conversation as resolved.
test $*
test "$@"
fi
}

while (( WAIT > 0 ))
do
if check_condition $*
if check_condition "$@"
then
if (( POST_WAIT > 0 ))
then
Expand Down