From: Martin Schwenke Date: Sat, 22 Jan 2022 19:42:52 +0000 (+1100) Subject: ctdb-tests: Factor out functions to detect when generation changes X-Git-Tag: tevent-0.12.0~721 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=265e44abc42e1f5b7fef6550cd748459dbef80cb;p=thirdparty%2Fsamba.git ctdb-tests: Factor out functions to detect when generation changes BUG: https://bugzilla.samba.org/show_bug.cgi?id=14958 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/tests/INTEGRATION/simple/cluster.015.reclock_remove_lock.sh b/ctdb/tests/INTEGRATION/simple/cluster.015.reclock_remove_lock.sh index 35363d11f1d..2283c30edbf 100755 --- a/ctdb/tests/INTEGRATION/simple/cluster.015.reclock_remove_lock.sh +++ b/ctdb/tests/INTEGRATION/simple/cluster.015.reclock_remove_lock.sh @@ -56,24 +56,14 @@ echo leader_get "$test_node" -echo "Get initial generation" -ctdb_onnode "$test_node" status -# shellcheck disable=SC2154 -# $outfile set by ctdb_onnode() above -generation_init=$(sed -n -e 's/^Generation:\([0-9]*\)/\1/p' "$outfile") -echo "Initial generation is ${generation_init}" -echo +generation_get echo "Remove recovery lock" rm "$reclock" echo # This will mean an election has taken place and a recovery has occured -echo "Wait until generation changes" -wait_until 30 generation_has_changed "$test_node" "$generation_init" -echo -echo "Generation changed to ${generation_new}" -echo +wait_until_generation_has_changed "$test_node" # shellcheck disable=SC2154 # $leader set by leader_get() above diff --git a/ctdb/tests/scripts/integration.bash b/ctdb/tests/scripts/integration.bash index 25ee4d945cc..eb3db1e1849 100644 --- a/ctdb/tests/scripts/integration.bash +++ b/ctdb/tests/scripts/integration.bash @@ -688,6 +688,50 @@ wait_until_leader_has_changed () ####################################### +# sets: generation +_generation_get () +{ + local node="$1" + + ctdb_onnode "$node" status + # shellcheck disable=SC2154 + # $outfile set by ctdb_onnode() above + generation=$(sed -n -e 's/^Generation:\([0-9]*\)/\1/p' "$outfile") +} + +generation_get () +{ + local node="$1" + + echo "Get generation" + _generation_get "$node" + echo "Generation is ${generation}" + echo +} + +_generation_has_changed () +{ + local node="$1" + local generation_old="$2" + + _generation_get "$node" + + [ "$generation" != "$generation_old" ] +} + +# uses: generation +wait_until_generation_has_changed () +{ + local node="$1" + + echo "Wait until generation changes..." + wait_until 30 _generation_has_changed "$node" "$generation" + echo "Generation changed to ${generation}" + echo +} + +####################################### + wait_for_monitor_event () { local pnn="$1"