-
Notifications
You must be signed in to change notification settings - Fork 49
/
kvs-helper.sh
executable file
·65 lines (57 loc) · 1.39 KB
/
kvs-helper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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)
}