-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/sh | ||
# | ||
|
||
# KVS Watch helper functions | ||
|
||
# Various loops to wait for conditions before moving on. There is | ||
# potential for racing between backgrounding processes and foreground | ||
# activities. | ||
# | ||
# Loop on KVS_WAIT_ITERS is just to make sure we don't spin forever on | ||
# error. | ||
|
||
KVS_WAIT_ITERS=50 | ||
|
||
loophandlereturn() { | ||
index=$1 | ||
if [ "$index" -eq "${KVS_WAIT_ITERS}" ] | ||
then | ||
return 1 | ||
fi | ||
return 0 | ||
} | ||
|
||
# arg1 - key to retrieve | ||
# arg2 - expected value | ||
test_kvs_key() { | ||
flux kvs get --json "$1" >output | ||
echo "$2" >expected | ||
test_cmp expected output | ||
} | ||
|
||
# arg1 - key to retrieve | ||
# arg2 - value to wait for | ||
wait_watch_put() { | ||
i=0 | ||
while [ "$(flux kvs get --json $1 2> /dev/null)" != "$2" ] && [ $i -lt ${KVS_WAIT_ITERS} ] | ||
do | ||
sleep 0.1 | ||
i=$((i + 1)) | ||
done | ||
return $(loophandlereturn $i) | ||
} | ||
|
||
# arg1 - key to retrieve | ||
wait_watch_empty() { | ||
i=0 | ||
while flux kvs get --json $1 2> /dev/null && [ $i -lt ${KVS_WAIT_ITERS} ] | ||
do | ||
sleep 0.1 | ||
i=$((i + 1)) | ||
done | ||
return $(loophandlereturn $i) | ||
} | ||
|
||
# arg1 - file to watch | ||
# arg2 - value to wait for | ||
wait_watch_file() { | ||
i=0 | ||
while [ "$(tail -n 1 $1 2> /dev/null)" != "$2" ] && [ $i -lt ${KVS_WAIT_ITERS} ] | ||
do | ||
sleep 0.1 | ||
i=$((i + 1)) | ||
done | ||
return $(loophandlereturn $i) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.