From c24fef859b84213393d09cfc2c7bf9f73d5f0604 Mon Sep 17 00:00:00 2001 From: anton Date: Fri, 5 Jan 2024 10:37:54 +0000 Subject: [PATCH] Wait until the expected interface state is reached instead of relying on arbitrary sleeps. Should hopefully make these tests more stable. --- regress/sys/netinet/carp/carp_1.sh | 6 +++--- regress/sys/netinet/carp/carp_2.sh | 6 +++--- regress/sys/netinet/carp/carp_3.sh | 6 +++--- regress/sys/netinet/carp/carp_4.sh | 6 +++--- regress/sys/netinet/carp/carp_subr | 13 +++++++++++++ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/regress/sys/netinet/carp/carp_1.sh b/regress/sys/netinet/carp/carp_1.sh index 76cf607ae22..28d685eb778 100644 --- a/regress/sys/netinet/carp/carp_1.sh +++ b/regress/sys/netinet/carp/carp_1.sh @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: carp_1.sh,v 1.2 2023/10/19 18:36:41 anton Exp $ +# $OpenBSD: carp_1.sh,v 1.3 2024/01/05 10:37:54 anton Exp $ cleanup() @@ -78,13 +78,13 @@ ifconfig carp$IFNO2 rdomain $RD2 192.168.0.1/24 \ # # IFNO1 must become master -sleep 3.1 # need 3 seconds to become master +wait_until "ifconfig carp$IFNO1 | grep -q 'status: master'" test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'" test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'" # carpdemote must work ifconfig -g ${IFGPREFIX}a carpdemote -sleep 0.1 +wait_until "ifconfig carp$IFNO1 | grep -q 'status: backup'" test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'" test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'" diff --git a/regress/sys/netinet/carp/carp_2.sh b/regress/sys/netinet/carp/carp_2.sh index 2cd53f0f47c..ce877509dd7 100644 --- a/regress/sys/netinet/carp/carp_2.sh +++ b/regress/sys/netinet/carp/carp_2.sh @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: carp_2.sh,v 1.2 2023/10/19 18:36:41 anton Exp $ +# $OpenBSD: carp_2.sh,v 1.3 2024/01/05 10:37:54 anton Exp $ cleanup() @@ -81,13 +81,13 @@ ifconfig carp$IFNO2 rdomain $RD2 lladdr $lladdr2 192.168.0.1/24 \ # # IFNO1 must become master -sleep 3.1 # need 3 seconds to become master +wait_until "ifconfig carp$IFNO1 | grep -q 'status: master'" test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'" test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'" # carpdemote must work ifconfig -g ${IFGPREFIX}a carpdemote -sleep 0.1 +wait_until "ifconfig carp$IFNO1 | grep -q 'status: backup'" test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'" test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'" diff --git a/regress/sys/netinet/carp/carp_3.sh b/regress/sys/netinet/carp/carp_3.sh index 3b2dc2c7854..ca7774c391e 100644 --- a/regress/sys/netinet/carp/carp_3.sh +++ b/regress/sys/netinet/carp/carp_3.sh @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: carp_3.sh,v 1.2 2023/10/19 18:36:41 anton Exp $ +# $OpenBSD: carp_3.sh,v 1.3 2024/01/05 10:37:54 anton Exp $ cleanup() @@ -78,13 +78,13 @@ ifconfig carp$IFNO2 rdomain $RD2 192.168.0.1/24 \ # # IFNO1 must become master -sleep 3.1 # need 3 seconds to become master +wait_until "ifconfig carp$IFNO1 | grep -q 'status: master'" test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'" test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'" # carpdemote must work ifconfig -g ${IFGPREFIX}a carpdemote -sleep 0.1 +wait_until "ifconfig carp$IFNO1 | grep -q 'status: backup'" test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'" test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'" diff --git a/regress/sys/netinet/carp/carp_4.sh b/regress/sys/netinet/carp/carp_4.sh index 98c2d6a55a8..56eab1dddae 100644 --- a/regress/sys/netinet/carp/carp_4.sh +++ b/regress/sys/netinet/carp/carp_4.sh @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: carp_4.sh,v 1.2 2023/10/19 18:36:41 anton Exp $ +# $OpenBSD: carp_4.sh,v 1.3 2024/01/05 10:37:54 anton Exp $ cleanup() @@ -81,13 +81,13 @@ ifconfig carp$IFNO2 rdomain $RD2 lladdr $lladdr2 192.168.0.1/24 \ # # IFNO1 must become master -sleep 3.1 # need 3 seconds to become master +wait_until "ifconfig carp$IFNO1 | grep -q 'status: master'" test sh -c "ifconfig carp$IFNO1 | grep -q 'status: master'" test sh -c "ifconfig carp$IFNO2 | grep -q 'status: backup'" # carpdemote must work ifconfig -g ${IFGPREFIX}a carpdemote -sleep 0.1 +wait_until "ifconfig carp$IFNO1 | grep -q 'status: backup'" test sh -c "ifconfig carp$IFNO1 | grep -q 'status: backup'" test sh -c "ifconfig carp$IFNO2 | grep -q 'status: master'" diff --git a/regress/sys/netinet/carp/carp_subr b/regress/sys/netinet/carp/carp_subr index fb86ca6b67c..e3456c79df0 100644 --- a/regress/sys/netinet/carp/carp_subr +++ b/regress/sys/netinet/carp/carp_subr @@ -55,6 +55,19 @@ test() fi } +wait_until() { + local _i=0 + + while [ "$_i" -lt 8 ]; do + sh -c "$@" && return 0 + sleep 0.5 + _i="$((_i + 1))" + done + echo timeout + return 1 +} + + RDOMAINS="" IFACE_NUMS="" while getopts 'cvR:I:' ch "$@"; do -- 2.20.1