From: Ondřej Surý Date: Sat, 16 Nov 2019 07:14:04 +0000 (+0800) Subject: Instead of sleeping for a fixed time, wait for named to log specific message in a... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc6604424609f18a661338a2c75d5e7c1c4516ed;p=thirdparty%2Fbind9.git Instead of sleeping for a fixed time, wait for named to log specific message in a loop --- diff --git a/bin/tests/system/runtime/tests.sh b/bin/tests/system/runtime/tests.sh index 4a5ee1ea03f..1223f15a9e7 100644 --- a/bin/tests/system/runtime/tests.sh +++ b/bin/tests/system/runtime/tests.sh @@ -44,6 +44,21 @@ kill_named() { return 0 } +wait_for_named() { + retries=10 + while [ "$retries" -gt 0 ]; do + if grep "$@" >/dev/null 2>&1; then + break + fi + sleep 1 + retries=$((retries-1)) + done + if [ "$retries" -eq 0 ]; then + return 1 + fi + return 0 +} + status=0 n=0 @@ -59,18 +74,17 @@ status=$((status+ret)) n=$((n+1)) echo_i "verifying that named checks for conflicting named processes ($n)" ret=0 -(cd ns2 && $NAMED -c named-alt2.conf -D runtime-ns2-extra-2 -X named.lock -m record,size,mctx -d 99 -g -U 4 >> named3.run 2>&1 & ) -sleep 2 -grep "another named process" ns2/named3.run > /dev/null || ret=1 +(cd ns2 && $NAMED -c named-alt2.conf -D runtime-ns2-extra-2 -X named.lock -m record,size,mctx -d 99 -g -U 4 >> named$n.run 2>&1 & ) +wait_for_named "another named process" ns2/named$n.run || ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status+ret)) n=$((n+1)) echo_i "verifying that 'lock-file none' disables process check ($n)" ret=0 -(cd ns2 && $NAMED -c named-alt3.conf -D runtime-ns2-extra-3 -m record,size,mctx -d 99 -g -U 4 >> named4.run 2>&1 & ) -sleep 2 -grep "another named process" ns2/named4.run > /dev/null && ret=1 +(cd ns2 && $NAMED -c named-alt3.conf -D runtime-ns2-extra-3 -m record,size,mctx -d 99 -g -U 4 >> named$n.run 2>&1 & ) +wait_for_named "running$" ns2/named$n.run || ret=1 +grep "another named process" ns2/named$n.run > /dev/null && ret=1 kill_named ns2/named-alt3.pid || ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status+ret)) @@ -121,10 +135,9 @@ status=$((status+ret)) n=$((n+1)) echo_i "checking that named refuses to start if working directory is not writable ($n)" ret=0 -(cd ns2 && $NAMED -c named-alt4.conf -D runtime-ns2-extra-4 -d 99 -g > named4.run 2>&1 &) -sleep 2 -grep "[^-]directory './nope' is not writable" ns2/named4.run > /dev/null 2>&1 || ret=1 -grep "exiting (due to fatal error)" ns2/named4.run > /dev/null || ret=1 +(cd ns2 && $NAMED -c named-alt4.conf -D runtime-ns2-extra-4 -d 99 -g > named$n.run 2>&1 &) +wait_for_named "exiting (due to fatal error)" ns2/named$n.run || ret=1 +grep "[^-]directory './nope' is not writable" ns2/named$n.run > /dev/null 2>&1 || ret=1 kill_named ns2/named.pid && ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status+ret)) @@ -132,10 +145,9 @@ status=$((status+ret)) n=$((n+1)) echo_i "checking that named refuses to start if managed-keys-directory is not writable ($n)" ret=0 -(cd ns2 && $NAMED -c named-alt5.conf -D runtime-ns2-extra-5 -d 99 -g > named5.run 2>&1 &) -sleep 2 -grep "managed-keys-directory './nope' is not writable" ns2/named5.run > /dev/null 2>&1 || ret=1 -grep "exiting (due to fatal error)" ns2/named5.run > /dev/null || ret=1 +(cd ns2 && $NAMED -c named-alt5.conf -D runtime-ns2-extra-5 -d 99 -g > named$n.run 2>&1 &) +wait_for_named "exiting (due to fatal error)" ns2/named$n.run || ret=1 +grep "managed-keys-directory './nope' is not writable" ns2/named$n.run > /dev/null 2>&1 || ret=1 kill_named named.pid && ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status+ret)) @@ -143,10 +155,9 @@ status=$((status+ret)) n=$((n+1)) echo_i "checking that named refuses to start if new-zones-directory is not writable ($n)" ret=0 -(cd ns2 && $NAMED -c named-alt6.conf -D runtime-ns2-extra-6 -d 99 -g > named6.run 2>&1 &) -sleep 2 -grep "new-zones-directory './nope' is not writable" ns2/named6.run > /dev/null 2>&1 || ret=1 -grep "exiting (due to fatal error)" ns2/named6.run > /dev/null || ret=1 +(cd ns2 && $NAMED -c named-alt6.conf -D runtime-ns2-extra-6 -d 99 -g > named$n.run 2>&1 &) +wait_for_named "exiting (due to fatal error)" ns2/named$n.run || ret=1 +grep "new-zones-directory './nope' is not writable" ns2/named$n.run > /dev/null 2>&1 || ret=1 kill_named ns2/named.pid && ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status+ret)) @@ -157,9 +168,9 @@ ret=0 SPEC_DIR=$(cat ctrl-char-dir-name) mkdir "ns2/${SPEC_DIR}" copy_setports ns2/named-alt7.conf.in "ns2/${SPEC_DIR}/named.conf" -(cd ns2 && $NAMED -c "${SPEC_DIR}/named.conf" -d 99 -g > named7.run 2>&1 &) -sleep 2 -grep 'running as.*\\177\\033' ns2/named7.run > /dev/null || ret=1 +(cd ns2 && $NAMED -c "${SPEC_DIR}/named.conf" -d 99 -g > named$n.run 2>&1 &) +wait_for_named "running$" ns2/named$n.run || ret=1 +grep 'running as.*\\177\\033' ns2/named$n.run > /dev/null || ret=1 kill_named ns2/named.pid || ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status+ret)) @@ -170,9 +181,9 @@ ret=0 SPEC_DIR="$;" mkdir "ns2/${SPEC_DIR}" copy_setports ns2/named-alt7.conf.in "ns2/${SPEC_DIR}/named.conf" -(cd ns2 && $NAMED -c "${SPEC_DIR}/named.conf" -d 99 -g > named8.run 2>&1 &) -sleep 2 -grep 'running as.*\\$\\;' ns2/named8.run > /dev/null || ret=1 +(cd ns2 && $NAMED -c "${SPEC_DIR}/named.conf" -d 99 -g > named$n.run 2>&1 &) +wait_for_named "running$" ns2/named$n.run || ret=1 +grep 'running as.*\\$\\;' ns2/named$n.run > /dev/null || ret=1 kill_named ns2/named.pid || ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status+ret)) @@ -183,9 +194,9 @@ ret=0 LONG_CMD_LINE=$(cat long-cmd-line) copy_setports ns2/named-alt7.conf.in "ns2/named-alt7.conf" # shellcheck disable=SC2086 -(cd ns2 && $NAMED $LONG_CMD_LINE -c "named-alt7.conf" -g > named9.run 2>&1 &) -sleep 2 -#grep "running as.*\.\.\.$" ns2/named9.run > /dev/null || ret=1 +(cd ns2 && $NAMED $LONG_CMD_LINE -c "named-alt7.conf" -g > named$n.run 2>&1 &) +wait_for_named "running$" ns2/named$n.run || ret=1 +#grep "running as.*\.\.\.$" ns2/named$n.run > /dev/null || ret=1 echo_i "skipped - the ellipsis is currently not printed" kill_named ns2/named.pid || ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi