Skip to content

Commit

Permalink
Merge 9475591 into d29b0cd
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed Jan 4, 2018
2 parents d29b0cd + 9475591 commit e1e765f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 129 deletions.
3 changes: 2 additions & 1 deletion t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ dist_check_SCRIPTS = \
scripts/waitfile.lua \
scripts/t0004-event-helper.sh \
scripts/tssh \
valgrind/valgrind-workload.sh
valgrind/valgrind-workload.sh \
kvs/kvs-helper.sh

test_ldadd = \
$(top_builddir)/src/common/libflux-internal.la \
Expand Down
65 changes: 65 additions & 0 deletions t/kvs/kvs-helper.sh
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)
}
8 changes: 2 additions & 6 deletions t/t1000-kvs.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ These are the basic/core flux kvs tests and should be run before
any other tests that require kvs functionality.
'

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

. `dirname $0`/sharness.sh

if test "$TEST_LONG" = "t"; then
Expand All @@ -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
#
Expand Down
73 changes: 13 additions & 60 deletions t/t1002-kvs-watch.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

test_description='kvs watch tests in flux session'

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

. `dirname $0`/sharness.sh

if test "$TEST_LONG" = "t"; then
Expand All @@ -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.
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand All @@ -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 &&
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit e1e765f

Please sign in to comment.