mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-27 14:29:51 +00:00
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:
parent
08e02b18db
commit
19aed8ecb5
23
testdefs.sh
23
testdefs.sh
@ -188,13 +188,31 @@ push_instance() {
|
|||||||
instance_stack+=("$instance_name")
|
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:
|
# Utility function:
|
||||||
# - pop an instance off the instance stack
|
# - pop an instance off the instance stack
|
||||||
pop_instance() {
|
pop_instance() {
|
||||||
local n=${#instance_stack[*]}
|
local n=${#instance_stack[*]}
|
||||||
[ $n -eq 0 ] && error "instance stack underflow"
|
if [ $n -eq 0 ]; then
|
||||||
|
error "instance stack underflow"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
let --n
|
let --n
|
||||||
|
set_instance +${instance_stack[$n]}
|
||||||
unset instance_stack[$n]
|
unset instance_stack[$n]
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Utility function:
|
# Utility function:
|
||||||
@ -207,6 +225,7 @@ set_instance() {
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
'')
|
'')
|
||||||
error "missing instance name argument"
|
error "missing instance name argument"
|
||||||
|
return 1
|
||||||
;;
|
;;
|
||||||
+[A-Z])
|
+[A-Z])
|
||||||
instance_arg="${1}"
|
instance_arg="${1}"
|
||||||
@ -228,9 +247,11 @@ set_instance() {
|
|||||||
export SERVALINSTANCE_PATH="$instance_dir/servald"
|
export SERVALINSTANCE_PATH="$instance_dir/servald"
|
||||||
instance_servald_log="$instance_dir/servald.log"
|
instance_servald_log="$instance_dir/servald.log"
|
||||||
instance_servald_pidfile="$SERVALINSTANCE_PATH/servald.pid"
|
instance_servald_pidfile="$SERVALINSTANCE_PATH/servald.pid"
|
||||||
|
return 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "malformed instance name argument, must be in form +[A-Z]"
|
error "malformed instance name argument, must be in form +[A-Z]"
|
||||||
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
@ -347,7 +347,7 @@ rhizome_http_server_started() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_rhizome_server_port() {
|
get_rhizome_server_port() {
|
||||||
set_instance $2
|
push_and_set_instance $2 || return $?
|
||||||
local _var="$1"
|
local _var="$1"
|
||||||
local _port=$(<"$SERVALINSTANCE_PATH/proc/http_port")
|
local _port=$(<"$SERVALINSTANCE_PATH/proc/http_port")
|
||||||
assert --message="instance $instance_name Rhizome HTTP server port number is known" [ -n "$_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"
|
eval "$_var=\$_port"
|
||||||
tfw_log "$_var=$_port"
|
tfw_log "$_var=$_port"
|
||||||
fi
|
fi
|
||||||
|
pop_instance
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +375,7 @@ bundle_received_by() {
|
|||||||
$restart && rexps=() bundles=()
|
$restart && rexps=() bundles=()
|
||||||
restart=false
|
restart=false
|
||||||
bid="${arg%%:*}"
|
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")
|
bundles+=("$arg")
|
||||||
if [ "$bid" = "$arg" ]; then
|
if [ "$bid" = "$arg" ]; then
|
||||||
rexps+=("RHIZOME ADD MANIFEST service=.* bid=$bid")
|
rexps+=("RHIZOME ADD MANIFEST service=.* bid=$bid")
|
||||||
@ -384,8 +385,7 @@ bundle_received_by() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
+[A-Z])
|
+[A-Z])
|
||||||
push_instance
|
tfw_nolog push_and_set_instance $arg || return $?
|
||||||
tfw_nolog set_instance $arg || return $?
|
|
||||||
tfw_nolog assert_servald_server_status running
|
tfw_nolog assert_servald_server_status running
|
||||||
for ((i = 0; i < ${#bundles[*]}; ++i)); do
|
for ((i = 0; i < ${#bundles[*]}; ++i)); do
|
||||||
bundle="${bundles[$i]}"
|
bundle="${bundles[$i]}"
|
||||||
@ -488,4 +488,3 @@ assert_rhizome_received() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,13 +38,11 @@ teardown() {
|
|||||||
|
|
||||||
is_published() {
|
is_published() {
|
||||||
tfw_log "grep \"PUBLISHED.*$1\" $instance_servald_log"
|
tfw_log "grep \"PUBLISHED.*$1\" $instance_servald_log"
|
||||||
grep "PUBLISHED.*$1" $instance_servald_log || return 1
|
grep "PUBLISHED.*$1" $instance_servald_log
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sent_directory_request() {
|
sent_directory_request() {
|
||||||
grep "Sending directory registration" $instance_servald_log || return 1
|
grep "Sending directory registration" $instance_servald_log
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_publish() {
|
setup_publish() {
|
||||||
@ -70,14 +68,12 @@ doc_publish="Publish and retrieve a directory entry"
|
|||||||
test_publish() {
|
test_publish() {
|
||||||
wait_until grep "DNAHELPER got STARTED ACK" $LOGA
|
wait_until grep "DNAHELPER got STARTED ACK" $LOGA
|
||||||
foreach_instance +B +C +D wait_until sent_directory_request
|
foreach_instance +B +C +D wait_until sent_directory_request
|
||||||
set_instance +A
|
|
||||||
wait_until is_published $SIDB
|
wait_until is_published $SIDB
|
||||||
wait_until is_published $SIDC
|
wait_until is_published $SIDC
|
||||||
wait_until is_published $SIDD
|
wait_until is_published $SIDD
|
||||||
stop_servald_server +B
|
stop_servald_server +B
|
||||||
stop_servald_server +C
|
stop_servald_server +C
|
||||||
stop_servald_server +D
|
stop_servald_server +D
|
||||||
set_instance +A
|
|
||||||
executeOk_servald dna lookup "$DIDB"
|
executeOk_servald dna lookup "$DIDB"
|
||||||
assertStdoutLineCount '==' 3
|
assertStdoutLineCount '==' 3
|
||||||
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
|
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
|
||||||
|
@ -26,6 +26,7 @@ setup() {
|
|||||||
assert_no_servald_processes
|
assert_no_servald_processes
|
||||||
setup_dnahelper
|
setup_dnahelper
|
||||||
start_servald_instances +A
|
start_servald_instances +A
|
||||||
|
set_instance +A
|
||||||
}
|
}
|
||||||
|
|
||||||
finally() {
|
finally() {
|
||||||
@ -230,6 +231,7 @@ setup_ExecError() {
|
|||||||
dnahelper=/non/existent
|
dnahelper=/non/existent
|
||||||
assert [ ! -e "$dnahelper" ]
|
assert [ ! -e "$dnahelper" ]
|
||||||
start_servald_instances +A
|
start_servald_instances +A
|
||||||
|
set_instance +A
|
||||||
}
|
}
|
||||||
test_ExecError() {
|
test_ExecError() {
|
||||||
executeOk_servald dna lookup 12345
|
executeOk_servald dna lookup 12345
|
||||||
@ -255,6 +257,7 @@ done
|
|||||||
EOF
|
EOF
|
||||||
chmod 0755 "$dnahelper"
|
chmod 0755 "$dnahelper"
|
||||||
start_servald_instances +A
|
start_servald_instances +A
|
||||||
|
set_instance +A
|
||||||
}
|
}
|
||||||
test_ExecArgs() {
|
test_ExecArgs() {
|
||||||
executeOk_servald dna lookup 12345
|
executeOk_servald dna lookup 12345
|
||||||
|
Loading…
x
Reference in New Issue
Block a user