Skip to content
Permalink
Browse files

Merge 3116a81 into d29b0cd

  • Loading branch information
chu11 committed Jan 3, 2018
2 parents d29b0cd + 3116a81 commit 0df367f271ce0152d8f771acd648e19a39eb1d51
Showing with 108 additions and 128 deletions.
  1. +65 −0 t/kvs/kvs-helper.sh
  2. +2 −6 t/t1000-kvs.t
  3. +13 −60 t/t1002-kvs-watch.t
  4. +28 −62 t/t1004-kvs-namespace.t
@@ -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)
}
@@ -7,6 +7,8 @@ These are the basic/core flux kvs tests and should be run before
any other tests that require kvs functionality.
'

source `dirname $0`/kvs/kvs-helper.sh

. `dirname $0`/sharness.sh

if test "$TEST_LONG" = "t"; then
@@ -23,12 +25,6 @@ KEY=test.a.b.c
SUBDIR1=test.a.b.d
SUBDIR2=test.a.b.e

test_kvs_key() {
flux kvs get --json "$1" >output
echo "$2" >expected
test_cmp expected output
}

#
# Basic put, get, unlink tests
#
@@ -3,6 +3,8 @@

test_description='kvs watch tests in flux session'

source `dirname $0`/kvs/kvs-helper.sh

. `dirname $0`/sharness.sh

if test "$TEST_LONG" = "t"; then
@@ -16,55 +18,6 @@ echo "# $0: flux session size will be ${SIZE}"

DIR=test.a.b

# Various loops to wait for conditions before moving on. Have
# observed racing between backgrounding watch process and foreground
# activities.
#
# Loop count is just to make sure we don't spin forever on error, 50
# loops/5 seconds seems like a decent maximum.

wait_watch_put() {
i=0
while [ "$(flux kvs get --json $1 2> /dev/null)" != "$2" ] && [ $i -lt 50 ]
do
sleep 0.1
i=$((i + 1))
done
if [ $i -eq 50 ]
then
return 1
fi
return 0
}

wait_watch_empty() {
i=0
while flux kvs get --json $1 2> /dev/null && [ $i -lt 50 ]
do
sleep 0.1
i=$((i + 1))
done
if [ $i -eq 50 ]
then
return 1
fi
return 0
}

wait_watch_current() {
i=0
while [ "$(tail -n 1 watch_out 2> /dev/null)" != "$1" ] && [ $i -lt 50 ]
do
sleep 0.1
i=$((i + 1))
done
if [ $i -eq 50 ]
then
return 1
fi
return 0
}

# Note that we do not && after the final call to wait_watch_put or
# wait_watch_empty. We want that as a barrier before launching our
# background watch process.
@@ -79,7 +32,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a key' '
rm -f watch_out
stdbuf -oL flux kvs watch -o -c 1 $DIR.foo >watch_out &
watchpid=$! &&
wait_watch_current "0"
wait_watch_file watch_out "0"
flux kvs put --json $DIR.foo=1 &&
wait $watchpid
cat >expected <<-EOF &&
@@ -95,7 +48,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a key that at first doesnt exist'
rm -f watch_out
stdbuf -oL flux kvs watch -o -c 1 $DIR.foo >watch_out &
watchpid=$! &&
wait_watch_current "nil" &&
wait_watch_file watch_out "nil" &&
flux kvs put --json $DIR.foo=1 &&
wait $watchpid
cat >expected <<-EOF &&
@@ -112,7 +65,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a key that gets removed' '
rm -f watch_out
stdbuf -oL flux kvs watch -o -c 1 $DIR.foo >watch_out &
watchpid=$!
wait_watch_current "0" &&
wait_watch_file watch_out "0" &&
flux kvs unlink $DIR.foo &&
wait $watchpid
cat >expected <<-EOF &&
@@ -129,7 +82,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a key that becomes a dir' '
rm -f watch_out
stdbuf -oL flux kvs watch -o -c 1 $DIR.foo >watch_out &
watchpid=$! &&
wait_watch_current "0" &&
wait_watch_file watch_out "0" &&
flux kvs put --json $DIR.foo.bar.baz=1 &&
wait $watchpid
cat >expected <<-EOF &&
@@ -149,7 +102,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a dir' '
rm -f watch_out
stdbuf -oL flux kvs watch -o -c 1 $DIR >watch_out &
watchpid=$! &&
wait_watch_current "======================" &&
wait_watch_file watch_out "======================" &&
flux kvs put --json $DIR.a.a=1 &&
wait $watchpid
cat >expected <<-EOF &&
@@ -167,7 +120,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a dir that at first doesnt exist'
rm -f watch_out
stdbuf -oL flux kvs watch -o -c 1 $DIR >watch_out &
watchpid=$! &&
wait_watch_current "nil" &&
wait_watch_file watch_out "nil" &&
flux kvs put --json $DIR.a.a=1 &&
wait $watchpid
cat >expected <<-EOF &&
@@ -187,7 +140,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a dir that gets removed' '
rm -f watch_out
stdbuf -oL flux kvs watch -o -c 1 $DIR.a >watch_out &
watchpid=$! &&
wait_watch_current "======================" &&
wait_watch_file watch_out "======================" &&
flux kvs unlink -R $DIR.a &&
wait $watchpid
cat >expected <<-EOF &&
@@ -207,7 +160,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a dir, converted into a key' '
rm -f watch_out
stdbuf -oL flux kvs watch -o -c 1 $DIR.a >watch_out &
watchpid=$! &&
wait_watch_current "======================" &&
wait_watch_file watch_out "======================" &&
flux kvs put --json $DIR.a=1 &&
wait $watchpid
cat >expected <<-EOF &&
@@ -230,7 +183,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a dir, prefix path converted into
rm -f watch_out
stdbuf -oL flux kvs watch -o -c 1 $DIR.a >watch_out &
watchpid=$! &&
wait_watch_current "======================" &&
wait_watch_file watch_out "======================" &&
flux kvs put --json $DIR=1 &&
wait $watchpid
cat >expected <<-EOF &&
@@ -270,7 +223,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a dir with -R' '
rm -f watch_out
stdbuf -oL flux kvs watch -R -o -c 1 $DIR >watch_out &
watchpid=$! &&
wait_watch_current "======================" &&
wait_watch_file watch_out "======================" &&
flux kvs put --json $DIR.a.a=1 &&
wait $watchpid
sort_watch_output
@@ -293,7 +246,7 @@ test_expect_success NO_CHAIN_LINT 'kvs: watch a dir with -R and -d' '
rm -f watch_out
stdbuf -oL flux kvs watch -R -d -o -c 1 $DIR >watch_out &
watchpid=$! &&
wait_watch_current "======================" &&
wait_watch_file watch_out "======================" &&
flux kvs put --json $DIR.a.a=1 &&
wait $watchpid
sort_watch_output

0 comments on commit 0df367f

Please sign in to comment.
You can’t perform that action at this time.