Fix test defs: pop_instance did not restore instance

Add push_and_set_instance() function
Remove redundant set_instance calls in test cases
Cope if error() returns (can happen during teardown)
This commit is contained in:
Andrew Bettison 2014-03-03 15:10:59 +10:30
parent 08e02b18db
commit 19aed8ecb5
4 changed files with 31 additions and 12 deletions

View File

@ -188,13 +188,31 @@ push_instance() {
instance_stack+=("$instance_name")
}
# Utility function:
# - push the current instance on the instance stack and set the instance to the
# given arg
# - if set_instance fails, pops the instance stack before returning
# set_instance's exit status
push_and_set_instance() {
push_instance
set_instance "$@" && return 0
status=$?
pop_instance
return $status
}
# Utility function:
# - pop an instance off the instance stack
pop_instance() {
local n=${#instance_stack[*]}
[ $n -eq 0 ] && error "instance stack underflow"
if [ $n -eq 0 ]; then
error "instance stack underflow"
return $?
fi
let --n
set_instance +${instance_stack[$n]}
unset instance_stack[$n]
return 0
}
# Utility function:
@ -207,6 +225,7 @@ set_instance() {
case "$1" in
'')
error "missing instance name argument"
return 1
;;
+[A-Z])
instance_arg="${1}"
@ -228,9 +247,11 @@ set_instance() {
export SERVALINSTANCE_PATH="$instance_dir/servald"
instance_servald_log="$instance_dir/servald.log"
instance_servald_pidfile="$SERVALINSTANCE_PATH/servald.pid"
return 0
;;
*)
error "malformed instance name argument, must be in form +[A-Z]"
return 1
;;
esac
}

View File

@ -347,7 +347,7 @@ rhizome_http_server_started() {
}
get_rhizome_server_port() {
set_instance $2
push_and_set_instance $2 || return $?
local _var="$1"
local _port=$(<"$SERVALINSTANCE_PATH/proc/http_port")
assert --message="instance $instance_name Rhizome HTTP server port number is known" [ -n "$_port" ]
@ -355,6 +355,7 @@ get_rhizome_server_port() {
eval "$_var=\$_port"
tfw_log "$_var=$_port"
fi
pop_instance
return 0
}
@ -374,7 +375,7 @@ bundle_received_by() {
$restart && rexps=() bundles=()
restart=false
bid="${arg%%:*}"
matches_rexp "$rexp_manifestid" "$bid" || error "invalid bundle ID: $bid"
matches_rexp "$rexp_manifestid" "$bid" || error "invalid bundle ID: $bid" || return $?
bundles+=("$arg")
if [ "$bid" = "$arg" ]; then
rexps+=("RHIZOME ADD MANIFEST service=.* bid=$bid")
@ -384,8 +385,7 @@ bundle_received_by() {
fi
;;
+[A-Z])
push_instance
tfw_nolog set_instance $arg || return $?
tfw_nolog push_and_set_instance $arg || return $?
tfw_nolog assert_servald_server_status running
for ((i = 0; i < ${#bundles[*]}; ++i)); do
bundle="${bundles[$i]}"
@ -488,4 +488,3 @@ assert_rhizome_received() {
fi
done
}

View File

@ -38,13 +38,11 @@ teardown() {
is_published() {
tfw_log "grep \"PUBLISHED.*$1\" $instance_servald_log"
grep "PUBLISHED.*$1" $instance_servald_log || return 1
return 0
grep "PUBLISHED.*$1" $instance_servald_log
}
sent_directory_request() {
grep "Sending directory registration" $instance_servald_log || return 1
return 0
grep "Sending directory registration" $instance_servald_log
}
setup_publish() {
@ -70,14 +68,12 @@ doc_publish="Publish and retrieve a directory entry"
test_publish() {
wait_until grep "DNAHELPER got STARTED ACK" $LOGA
foreach_instance +B +C +D wait_until sent_directory_request
set_instance +A
wait_until is_published $SIDB
wait_until is_published $SIDC
wait_until is_published $SIDD
stop_servald_server +B
stop_servald_server +C
stop_servald_server +D
set_instance +A
executeOk_servald dna lookup "$DIDB"
assertStdoutLineCount '==' 3
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"

View File

@ -26,6 +26,7 @@ setup() {
assert_no_servald_processes
setup_dnahelper
start_servald_instances +A
set_instance +A
}
finally() {
@ -230,6 +231,7 @@ setup_ExecError() {
dnahelper=/non/existent
assert [ ! -e "$dnahelper" ]
start_servald_instances +A
set_instance +A
}
test_ExecError() {
executeOk_servald dna lookup 12345
@ -255,6 +257,7 @@ done
EOF
chmod 0755 "$dnahelper"
start_servald_instances +A
set_instance +A
}
test_ExecArgs() {
executeOk_servald dna lookup 12345