Improve test scripts: use new 'wait_until' primitive

This commit is contained in:
Andrew Bettison 2012-07-11 16:43:21 +09:30
parent cc39a02443
commit 218e7883ce
2 changed files with 21 additions and 38 deletions

View File

@ -464,30 +464,9 @@ start_servald_instances() {
eval LOG${I#+}="$instance_servald_log"
done
# Now wait until they see each other.
local timeout_seconds=30
local timeout_retry_seconds=0.25
sleep $timeout_seconds &
local timeout_pid=$!
tfw_log "# wait for instances to see each other"
while true; do
local allseen=true
for I; do
for J; do
[ $I = $J ] && continue
local logvar=LOG${I#+}
local sidvar=SID${J#+}
if ! grep "ADD OVERLAY NODE sid=${!sidvar}" "${!logvar}"; then
allseen=false
break 2
fi
done
done
$allseen && break
kill -0 $timeout_pid 2>/dev/null || fail "timeout"
tfw_log "sleep $timeout_retry_seconds"
sleep $timeout_retry_seconds
done
wait_until --sleep=0.25 instances_see_each_other "$@"
tfw_log "# dummynet file:" $(ls -l $DUMMYNET)
# Assert that all instances report complete all-peer lists.
for I; do
set_instance $I
executeOk_servald id allpeers
@ -500,3 +479,18 @@ start_servald_instances() {
done
pop_instance
}
instances_see_each_other() {
local I J
for I; do
for J; do
[ $I = $J ] && continue
local logvar=LOG${I#+}
local sidvar=SID${J#+}
if ! grep "ADD OVERLAY NODE sid=${!sidvar}" "${!logvar}"; then
return 1
fi
done
done
return 0
}

View File

@ -38,7 +38,7 @@ setup_rhizome() {
create_rhizome_identities 1
}
# Called by start_servald_instances.
# Called by start_servald_instances for each instance.
configure_servald_server() {
executeOk_servald config set debug.rhizome on
executeOk_servald config set debug.rhizomesync on
@ -52,26 +52,15 @@ setup_FileTransferNew() {
setup_rhizome
assert_no_servald_processes
start_servald_instances +A +B
set_instance +A
echo 'File one' >file1
set_instance +A
executeOk_servald rhizome add file '' '' file1 file1.manifest
extract_manifest_id BID file1.manifest
extract_manifest_version VERSION file1.manifest
set_instance +B
}
test_FileTransferNew() {
sleep 30 &
local timeout_pid=$!
local timeout_retry_seconds=1
tfw_log "# wait for manifest to arrive"
while true; do
if grep "RHIZOME ADD MANIFEST service=file bid=$BID version=$VERSION" "$LOGB"; then
break
fi
kill -0 $timeout_pid 2>/dev/null || fail "timeout"
tfw_log "sleep $timeout_retry_seconds"
sleep $timeout_retry_seconds
done
set_instance +B
wait_until grep "RHIZOME ADD MANIFEST service=file bid=$BID version=$VERSION" "$LOGB"
executeOk_servald rhizome list ''
assert_rhizome_list file1!
}