diff mbox

[ovs-dev,add,ovsdb,lock,tests,3/3] tests: add ovsdb lock tests

Message ID 1465246276-78258-3-git-send-email-azhou@ovn.org
State Accepted
Headers show

Commit Message

Andy Zhou June 6, 2016, 8:51 p.m. UTC
Add more ovsdb lock tests.

Signed-off-by: Andy Zhou <azhou@ovn.org>
---
 tests/automake.mk   |  1 +
 tests/ovsdb-lock.at | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/ovsdb.at      |  1 +
 3 files changed, 79 insertions(+)
 create mode 100644 tests/ovsdb-lock.at

Comments

Ryan Moats June 23, 2016, 4:01 p.m. UTC | #1
"dev" <dev-bounces@openvswitch.org> wrote on 06/06/2016 03:51:16 PM:

> From: Andy Zhou <azhou@ovn.org>
> To: dev@openvswitch.com
> Date: 06/06/2016 03:52 PM
> Subject: [ovs-dev] [add ovsdb lock tests 3/3] tests: add ovsdb lock tests
> Sent by: "dev" <dev-bounces@openvswitch.org>
>
> Add more ovsdb lock tests.
>
> Signed-off-by: Andy Zhou <azhou@ovn.org>
> ---

I would have preferred for this patch to be combined with the previous
patch set in the series, but that is a nit and so this ack should be
considered to be an Ack for both parts 2 and 3 together.

Acked-by: Ryan Moats <rmoats@us.ibm.com>

Ryan
Ben Pfaff June 23, 2016, 7:31 p.m. UTC | #2
On Mon, Jun 06, 2016 at 01:51:16PM -0700, Andy Zhou wrote:
> Add more ovsdb lock tests.
> 
> Signed-off-by: Andy Zhou <azhou@ovn.org>

This test checks c1-output twice, I suspect that the second check should
be for c2-output:

> +#
> +# Two sessions create two locks. Both sessions should able get their own
> +# lock immediately.
> +OVSDB_CHECK_LOCK_SETUP([lock], [positive])
> +AT_CHECK([ovsdb-client --detach lock unix:socket lock0 >c1-output 2>&1],
> +      [0], [], [])
> +AT_CHECK([ovsdb-client --detach lock unix:socket lock1 >c2-output 2>&1],
> +      [0], [], [])
> +OVS_APP_EXIT_AND_WAIT(["`pwd`"/svr-unixctl])
> +OVS_WAIT_UNTIL([test ! -e server-pid])
> +AT_CHECK([cat c1-output], 0, [{"locked":true}
> +], [])
> +AT_CHECK([cat c1-output], 0, [{"locked":true}
> +], [])
> +AT_CLEANUP

Acked-by: Ben Pfaff <blp@ovn.org>
Andy Zhou July 22, 2016, 10:28 p.m. UTC | #3
On Thu, Jun 23, 2016 at 12:31 PM, Ben Pfaff <blp@ovn.org> wrote:

> On Mon, Jun 06, 2016 at 01:51:16PM -0700, Andy Zhou wrote:
> > Add more ovsdb lock tests.
> >
> > Signed-off-by: Andy Zhou <azhou@ovn.org>
>
> This test checks c1-output twice, I suspect that the second check should
> be for c2-output:
>
Good catch.  Fixed.

>
> > +#
> > +# Two sessions create two locks. Both sessions should able get their own
> > +# lock immediately.
> > +OVSDB_CHECK_LOCK_SETUP([lock], [positive])
> > +AT_CHECK([ovsdb-client --detach lock unix:socket lock0 >c1-output 2>&1],
> > +      [0], [], [])
> > +AT_CHECK([ovsdb-client --detach lock unix:socket lock1 >c2-output 2>&1],
> > +      [0], [], [])
> > +OVS_APP_EXIT_AND_WAIT(["`pwd`"/svr-unixctl])
> > +OVS_WAIT_UNTIL([test ! -e server-pid])
> > +AT_CHECK([cat c1-output], 0, [{"locked":true}
> > +], [])
> > +AT_CHECK([cat c1-output], 0, [{"locked":true}
> > +], [])
> > +AT_CLEANUP
>
> Acked-by: Ben Pfaff <blp@ovn.org>
>

Thanks Ryan and Ben for the review.  Pushed to master.
diff mbox

Patch

diff --git a/tests/automake.mk b/tests/automake.mk
index 7af7f69..44f5472 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -77,6 +77,7 @@  TESTSUITE_AT = \
 	tests/ovsdb-server.at \
 	tests/ovsdb-monitor.at \
 	tests/ovsdb-idl.at \
+	tests/ovsdb-lock.at \
 	tests/ovs-vsctl.at \
 	tests/ovs-monitor-ipsec.at \
 	tests/ovs-xapi-sync.at \
diff --git a/tests/ovsdb-lock.at b/tests/ovsdb-lock.at
new file mode 100644
index 0000000..78c0e98
--- /dev/null
+++ b/tests/ovsdb-lock.at
@@ -0,0 +1,77 @@ 
+AT_BANNER([OVSDB -- lock])
+
+# OVSDB_CHECK_LOCK_SETUP(TITILE, KEYWORDS)
+#
+# Starts an OVSDB server and the default lock transaction, acquire "lock0",
+# using the ovsdb-client tool.  Execute additional <LOCK_TRANSACTIONS>,
+# and compare output file catured from ovsdb-client tools to <OUTPUT>.
+
+m4_define([OVSDB_CHECK_LOCK_SETUP],
+   [AT_SETUP([ovsdb lock -- $1])
+    AT_SKIP_IF([test "$IS_WIN32" = "yes"])
+    AT_KEYWORDS([ovsdb lock $2])
+    ordinal_schema > schema
+    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
+    AT_CAPTURE_FILE([ovsdb-server-log])
+    AT_CHECK([ovsdb-server --detach --no-chdir --pidfile="`pwd`"/server-pid --remote=punix:socket --unixctl="`pwd`"/svr-unixctl --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1],
+            [0], [], [])])
+
+#
+# Two sessions create two locks. Both sessions should able get their own
+# lock immediately.
+OVSDB_CHECK_LOCK_SETUP([lock], [positive])
+AT_CHECK([ovsdb-client --detach lock unix:socket lock0 >c1-output 2>&1],
+      [0], [], [])
+AT_CHECK([ovsdb-client --detach lock unix:socket lock1 >c2-output 2>&1],
+      [0], [], [])
+OVS_APP_EXIT_AND_WAIT(["`pwd`"/svr-unixctl])
+OVS_WAIT_UNTIL([test ! -e server-pid])
+AT_CHECK([cat c1-output], 0, [{"locked":true}
+], [])
+AT_CHECK([cat c1-output], 0, [{"locked":true}
+], [])
+AT_CLEANUP
+
+#
+# Two session wait on the same lock. The first session should be able
+# to get the lock immediately, the second session will get a notification
+# after the first session unlocks.
+OVSDB_CHECK_LOCK_SETUP([unlock], [positive])
+AT_CHECK([ovsdb-client --detach --pidfile lock unix:socket lock0 >c1-output 2>&1],
+      [0], [], [])
+AT_CHECK([ovsdb-client --detach lock unix:socket lock0 >c2-output 2>&1],
+      [0], [], [])
+AT_CHECK([ovs-appctl -t ovsdb-client unlock lock0], [0], [], [])
+OVS_APP_EXIT_AND_WAIT(["`pwd`"/svr-unixctl])
+OVS_WAIT_UNTIL([test ! -e server-pid])
+AT_CHECK([cat c1-output], 0, [{"locked":true}
+{}
+])
+AT_CHECK([cat c2-output], 0, [{"locked":false}
+locked
+[["lock0"]]
+], [])
+AT_CLEANUP
+
+#
+# Two session waits on the same lock. The first session should be able
+# to get the lock immediately. The second session tries to steal the lock, then
+# unlocks the lock.
+OVSDB_CHECK_LOCK_SETUP([steal], [positive])
+AT_CHECK([ovsdb-client --detach lock unix:socket lock0 >c1-output 2>&1],
+      [0], [], [])
+AT_CHECK([ovsdb-client --detach --pidfile steal unix:socket lock0 >c2-output 2>&1],
+      [0], [], [])
+AT_CHECK([ovs-appctl -t ovsdb-client unlock lock0], [0], [], [])
+OVS_APP_EXIT_AND_WAIT(["`pwd`"/svr-unixctl])
+OVS_WAIT_UNTIL([test ! -e server-pid])
+AT_CHECK([cat c1-output], 0, [{"locked":true}
+stolen
+[["lock0"]]
+locked
+[["lock0"]]
+])
+AT_CHECK([cat c2-output], 0, [{"locked":true}
+{}
+], [])
+AT_CLEANUP
diff --git a/tests/ovsdb.at b/tests/ovsdb.at
index 5000713..6fe684c 100644
--- a/tests/ovsdb.at
+++ b/tests/ovsdb.at
@@ -146,3 +146,4 @@  m4_include([tests/ovsdb-tool.at])
 m4_include([tests/ovsdb-server.at])
 m4_include([tests/ovsdb-monitor.at])
 m4_include([tests/ovsdb-idl.at])
+m4_include([tests/ovsdb-lock.at])