The Samba-Bugzilla – Attachment 13730 Details for
Bug 13097
Avoid race conditions in unit tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for 4.7
BZ13097-v4-7.patch (text/plain), 9.49 KB, created by
Martin Schwenke
on 2017-10-26 23:27:34 UTC
(
hide
)
Description:
Patch for 4.7
Filename:
MIME Type:
Creator:
Martin Schwenke
Created:
2017-10-26 23:27:34 UTC
Size:
9.49 KB
patch
obsolete
>From b8482c2ab322e381fccf5726f9b7c372bd430828 Mon Sep 17 00:00:00 2001 >From: Martin Schwenke <martin@meltin.net> >Date: Wed, 25 Oct 2017 12:04:49 +1100 >Subject: [PATCH 1/5] ctdb-tests: Allow wait_until() to be used in unit tests > >BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 > >Signed-off-by: Martin Schwenke <martin@meltin.net> >Reviewed-by: Amitay Isaacs <amitay@gmail.com> >(cherry picked from commit d69899238bfe468cd3e915f6d66e279811301d66) >--- > ctdb/tests/scripts/common.sh | 44 +++++++++++++++++++++++++++++++++++++ > ctdb/tests/scripts/integration.bash | 44 ------------------------------------- > 2 files changed, 44 insertions(+), 44 deletions(-) > >diff --git a/ctdb/tests/scripts/common.sh b/ctdb/tests/scripts/common.sh >index 287fb71fd1d..e20b6d0ee7e 100644 >--- a/ctdb/tests/scripts/common.sh >+++ b/ctdb/tests/scripts/common.sh >@@ -43,3 +43,47 @@ die () > { > echo "$1" >&2 ; exit ${2:-1} > } >+ >+# Wait until either timeout expires or command succeeds. The command >+# will be tried once per second, unless timeout has format T/I, where >+# I is the recheck interval. >+wait_until () >+{ >+ local timeout="$1" ; shift # "$@" is the command... >+ >+ local interval=1 >+ case "$timeout" in >+ */*) >+ interval="${timeout#*/}" >+ timeout="${timeout%/*}" >+ esac >+ >+ local negate=false >+ if [ "$1" = "!" ] ; then >+ negate=true >+ shift >+ fi >+ >+ echo -n "<${timeout}|" >+ local t=$timeout >+ while [ $t -gt 0 ] ; do >+ local rc=0 >+ "$@" || rc=$? >+ if { ! $negate && [ $rc -eq 0 ] ; } || \ >+ { $negate && [ $rc -ne 0 ] ; } ; then >+ echo "|$(($timeout - $t))|" >+ echo "OK" >+ return 0 >+ fi >+ local i >+ for i in $(seq 1 $interval) ; do >+ echo -n . >+ done >+ t=$(($t - $interval)) >+ sleep $interval >+ done >+ >+ echo "*TIMEOUT*" >+ >+ return 1 >+} >diff --git a/ctdb/tests/scripts/integration.bash b/ctdb/tests/scripts/integration.bash >index 4f1227f4393..d72c471e41a 100644 >--- a/ctdb/tests/scripts/integration.bash >+++ b/ctdb/tests/scripts/integration.bash >@@ -259,50 +259,6 @@ delete_ip_from_all_nodes () > > ####################################### > >-# Wait until either timeout expires or command succeeds. The command >-# will be tried once per second, unless timeout has format T/I, where >-# I is the recheck interval. >-wait_until () >-{ >- local timeout="$1" ; shift # "$@" is the command... >- >- local interval=1 >- case "$timeout" in >- */*) >- interval="${timeout#*/}" >- timeout="${timeout%/*}" >- esac >- >- local negate=false >- if [ "$1" = "!" ] ; then >- negate=true >- shift >- fi >- >- echo -n "<${timeout}|" >- local t=$timeout >- while [ $t -gt 0 ] ; do >- local rc=0 >- "$@" || rc=$? >- if { ! $negate && [ $rc -eq 0 ] ; } || \ >- { $negate && [ $rc -ne 0 ] ; } ; then >- echo "|$(($timeout - $t))|" >- echo "OK" >- return 0 >- fi >- local i >- for i in $(seq 1 $interval) ; do >- echo -n . >- done >- t=$(($t - $interval)) >- sleep $interval >- done >- >- echo "*TIMEOUT*" >- >- return 1 >-} >- > sleep_for () > { > echo -n "=${1}|" >-- >2.14.2 > > >From 323c8f36b176b72cd23e1b4bcafc22b0845e10a8 Mon Sep 17 00:00:00 2001 >From: Martin Schwenke <martin@meltin.net> >Date: Wed, 25 Oct 2017 18:52:10 +1100 >Subject: [PATCH 2/5] ctdb-tests: Wait for ctdb_eventd to start, fail if it > doesn't > >BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 > >Signed-off-by: Martin Schwenke <martin@meltin.net> >Reviewed-by: Amitay Isaacs <amitay@gmail.com> >(cherry picked from commit dcbaebc232b49e6a64228f1bb7ce7cfc5d2120e2) >--- > ctdb/tests/eventd/scripts/local.sh | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > >diff --git a/ctdb/tests/eventd/scripts/local.sh b/ctdb/tests/eventd/scripts/local.sh >index 343205ecec4..c8f7775f554 100644 >--- a/ctdb/tests/eventd/scripts/local.sh >+++ b/ctdb/tests/eventd/scripts/local.sh >@@ -42,7 +42,7 @@ cleanup_eventd () > > setup_eventd () > { >- debug "Setting up eventd" >+ echo "Setting up eventd" > > if [ -n "$1" ]; then > extra_args="-D $1" >@@ -53,9 +53,8 @@ setup_eventd () > -e "$eventd_scriptdir" \ > -l "file:" -d "DEBUG" $extra_args 2>&1 | tee "$eventd_logfile" & > # Wait till eventd is running >- while [ ! -S "$eventd_socket" ] ; do >- sleep 1 >- done >+ wait_until 10 test -S "$eventd_socket" || \ >+ die "ctdb_eventd failed to start" > > test_cleanup cleanup_eventd > } >-- >2.14.2 > > >From 66e2509ab5aa2d50780765e3751a36447fa3abe0 Mon Sep 17 00:00:00 2001 >From: Martin Schwenke <martin@meltin.net> >Date: Wed, 25 Oct 2017 21:43:56 +1100 >Subject: [PATCH 3/5] ctdb-tests: Skip starting fake_ctdbd when current node is > disconnected > >BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 > >Signed-off-by: Martin Schwenke <martin@meltin.net> >Reviewed-by: Amitay Isaacs <amitay@gmail.com> >(cherry picked from commit 274fef9b843aa1726c9d331a876504bc0a96a322) >--- > ctdb/tests/tool/ctdb.getcapabilities.003.sh | 13 +++++++------ > ctdb/tests/tool/ctdb.lvs.008.sh | 13 +++++++------ > 2 files changed, 14 insertions(+), 12 deletions(-) > >diff --git a/ctdb/tests/tool/ctdb.getcapabilities.003.sh b/ctdb/tests/tool/ctdb.getcapabilities.003.sh >index 91d38b8c9e3..74702d5b5e7 100755 >--- a/ctdb/tests/tool/ctdb.getcapabilities.003.sh >+++ b/ctdb/tests/tool/ctdb.getcapabilities.003.sh >@@ -10,12 +10,13 @@ setup_nodes <<EOF > 192.168.20.43 > EOF > >-setup_ctdbd <<EOF >-NODEMAP >-0 192.168.20.41 0x1 CURRENT RECMASTER >-1 192.168.20.42 0x0 >-2 192.168.20.43 0x0 >-EOF >+# Don't setup ctdbd - disconnected on current node >+#setup_ctdbd <<EOF >+#NODEMAP >+#0 192.168.20.41 0x1 CURRENT RECMASTER >+#1 192.168.20.42 0x0 >+#2 192.168.20.43 0x0 >+#EOF > > required_result 1 <<EOF > connect() failed, errno=2 >diff --git a/ctdb/tests/tool/ctdb.lvs.008.sh b/ctdb/tests/tool/ctdb.lvs.008.sh >index a0e24b14afd..6cdd702c57c 100755 >--- a/ctdb/tests/tool/ctdb.lvs.008.sh >+++ b/ctdb/tests/tool/ctdb.lvs.008.sh >@@ -13,12 +13,13 @@ EOF > setup_lvs <<EOF > EOF > >-setup_ctdbd <<EOF >-NODEMAP >-0 192.168.20.41 0x1 CURRENT RECMASTER >-1 192.168.20.42 0x0 >-2 192.168.20.43 0x0 >-EOF >+# Don't setup ctdbd - disconnected on current node >+#setup_ctdbd <<EOF >+#NODEMAP >+#0 192.168.20.41 0x1 CURRENT RECMASTER >+#1 192.168.20.42 0x0 >+#2 192.168.20.43 0x0 >+#EOF > > ##### > >-- >2.14.2 > > >From 4f35f1ff6bef38a9da043402566c5a1607fbd72f Mon Sep 17 00:00:00 2001 >From: Martin Schwenke <martin@meltin.net> >Date: Wed, 25 Oct 2017 17:52:04 +1100 >Subject: [PATCH 4/5] ctdb-tests: Wait for fake_ctdbd to start, fail if it > doesn't > >BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 > >Signed-off-by: Martin Schwenke <martin@meltin.net> >Reviewed-by: Amitay Isaacs <amitay@gmail.com> >(cherry picked from commit 6fad42103c0c812d5b5f4b42854fd7fd68846487) >--- > ctdb/tests/tool/scripts/local.sh | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > >diff --git a/ctdb/tests/tool/scripts/local.sh b/ctdb/tests/tool/scripts/local.sh >index 2c9be2d324c..7cee84a2d4b 100644 >--- a/ctdb/tests/tool/scripts/local.sh >+++ b/ctdb/tests/tool/scripts/local.sh >@@ -48,10 +48,14 @@ cleanup_ctdbd () > > setup_ctdbd () > { >- debug "Setting up fake ctdbd" >+ echo "Setting up fake ctdbd" > > $VALGRIND fake_ctdbd -d "$FAKE_CTDBD_DEBUGLEVEL" \ > -s "$ctdbd_socket" -p "$ctdbd_pidfile" >+ # Wait till fake_ctdbd is running >+ wait_until 10 test -S "$ctdbd_socket" || \ >+ die "fake_ctdbd failed to start" >+ > test_cleanup cleanup_ctdbd > } > >-- >2.14.2 > > >From 5a125e5833134c86ee43273373bfdd86a538ba7d Mon Sep 17 00:00:00 2001 >From: Martin Schwenke <martin@meltin.net> >Date: Wed, 25 Oct 2017 12:15:23 +1100 >Subject: [PATCH 5/5] ctdb-tests: Process-exists unit tests should wait until > PID is registered > >Otherwise the client registration can race with the check in the test. > >BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 > >Signed-off-by: Martin Schwenke <martin@meltin.net> >Reviewed-by: Amitay Isaacs <amitay@gmail.com> > >Autobuild-User(master): Amitay Isaacs <amitay@samba.org> >Autobuild-Date(master): Thu Oct 26 13:32:24 CEST 2017 on sn-devel-144 > >(cherry picked from commit 0e8b781e0740310d251bf1fa7db7a467d4f7f9b5) >--- > ctdb/tests/tool/ctdb.process-exists.001.sh | 2 ++ > ctdb/tests/tool/ctdb.process-exists.002.sh | 2 ++ > ctdb/tests/tool/ctdb.process-exists.003.sh | 2 ++ > 3 files changed, 6 insertions(+) > >diff --git a/ctdb/tests/tool/ctdb.process-exists.001.sh b/ctdb/tests/tool/ctdb.process-exists.001.sh >index 2339344fec5..1b6d213b3ad 100755 >--- a/ctdb/tests/tool/ctdb.process-exists.001.sh >+++ b/ctdb/tests/tool/ctdb.process-exists.001.sh >@@ -14,6 +14,8 @@ EOF > dummy_client -s $ctdbd_socket & > pid=$! > >+wait_until 10 $CTDB process-exists "$pid" >+ > ok "PID $pid exists" > simple_test "$pid" > >diff --git a/ctdb/tests/tool/ctdb.process-exists.002.sh b/ctdb/tests/tool/ctdb.process-exists.002.sh >index fe3dfd4d59f..ace77493565 100755 >--- a/ctdb/tests/tool/ctdb.process-exists.002.sh >+++ b/ctdb/tests/tool/ctdb.process-exists.002.sh >@@ -16,6 +16,8 @@ srvid="0xaebbccdd12345678" > dummy_client -d INFO -s "$ctdbd_socket" -S "$srvid" & > pid=$! > >+wait_until 10 $CTDB process-exists "$pid" >+ > srvid2="0x1234567812345678" > required_result 1 "PID $pid with SRVID $srvid2 does not exist" > simple_test "$pid" "$srvid2" >diff --git a/ctdb/tests/tool/ctdb.process-exists.003.sh b/ctdb/tests/tool/ctdb.process-exists.003.sh >index bb1ef9ae940..29c42a1a627 100755 >--- a/ctdb/tests/tool/ctdb.process-exists.003.sh >+++ b/ctdb/tests/tool/ctdb.process-exists.003.sh >@@ -16,6 +16,8 @@ srvid="0xaebbccdd12345678" > dummy_client -d INFO -s "$ctdbd_socket" -n 10 -S "$srvid" & > pid=$! > >+wait_until 10 $CTDB process-exists "$pid" >+ > srvid2="0x1234567812345678" > required_result 1 "PID $pid with SRVID $srvid2 does not exist" > simple_test "$pid" "$srvid2" >-- >2.14.2 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Flags:
amitay
:
review+
Actions:
View
Attachments on
bug 13097
: 13730 |
13731