[ovs-dev] [replication SMv2 5/7] test: Improve replication unit tests

Andy Zhou azhou at ovn.org
Fri Aug 26 23:15:52 UTC 2016


Replication test currently uses many sleeps that slowes the test down
and may not be reliable. Remove those sleeps when possible.

OVSDB servers needs to be killed on test failure. Use on_exit() to
ensure cleanup happens, so they don't have to be handled for each
testing step.

Signed-off-by: Andy Zhou <azhou at ovn.org>
---
 tests/ovsdb-replication.at |  28 ++++++++---
 tests/ovsdb-server.at      | 115 ++++++++++++++++++++-------------------------
 2 files changed, 73 insertions(+), 70 deletions(-)

diff --git a/tests/ovsdb-replication.at b/tests/ovsdb-replication.at
index bd96ae7..e1e68b3 100644
--- a/tests/ovsdb-replication.at
+++ b/tests/ovsdb-replication.at
@@ -33,8 +33,12 @@ OVSDB_CHECK_REPLICATION([insert monitored table, insert excluded table],
   [[["mydb",
       {"op": "insert",
        "table": "b",
+       "row": {"number": 1, "name": "one"}}]]],
+  [[["mydb",
+      {"op": "insert",
+       "table": "a",
        "row": {"number": 1, "name": "one"}}]]]],
-  [[7,9c7,8
+  [[8,10c8,9
 < _uuid                                name number
 < ------------------------------------ ---- ------
 < <0> one  1     @&t@
@@ -57,8 +61,12 @@ OVSDB_CHECK_REPLICATION([insert monitored table, update excluded table],
       {"op": "update",
        "table": "b",
        "where":[["name","==","one"]],
-       "row": {"number": 2, "name": "two"}}]]]],
-  [[7,9c7,8
+       "row": {"number": 2, "name": "two"}}]]],
+  [[["mydb",
+      {"op": "insert",
+       "table": "a",
+       "row": {"number": 1, "name": "one"}}]]]],
+  [[8,10c8,9
 < _uuid                                name number
 < ------------------------------------ ---- ------
 < <0> two  2     @&t@
@@ -133,8 +141,12 @@ OVSDB_CHECK_REPLICATION([delete monitored table, insert excluded table],
   [[["mydb",
       {"op": "insert",
        "table": "b",
+       "row": {"number": 1, "name": "one"}}]]],
+  [[["mydb",
+      {"op": "insert",
+       "table": "a",
        "row": {"number": 1, "name": "one"}}]]]],
-  [[6,8c6,7
+  [[7,9c7,8
 < _uuid                                name number
 < ------------------------------------ ---- ------
 < <0> one  1     @&t@
@@ -161,8 +173,12 @@ OVSDB_CHECK_REPLICATION([delete monitored table, update excluded table],
       {"op": "update",
        "table": "b",
        "where":[["name","==","one"]],
-       "row": {"number": 2, "name": "two"}}]]]],
-  [[6,8c6,7
+       "row": {"number": 2, "name": "two"}}]]],
+  [[["mydb",
+      {"op": "insert",
+       "table": "a",
+       "row": {"number": 1, "name": "one"}}]]]],
+  [[7,9c7,8
 < _uuid                                name number
 < ------------------------------------ ---- ------
 < <0> two  2     @&t@
diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at
index c1e7d96..d2f3089 100644
--- a/tests/ovsdb-server.at
+++ b/tests/ovsdb-server.at
@@ -999,23 +999,19 @@ m4_define([OVSDB_CHECK_EXECUTION],
    AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
 
    AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
+   i
+   on_exit 'test ! -e pid || kill `cat pid`'
 
    AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
+   on_exit 'test ! -e pid2 || kill `cat pid2`'
 
    m4_foreach([txn], [$3],
-     [AT_CHECK([ovsdb-client transact 'txn'; sleep 2], [0], [stdout], [ignore],
-     [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+     [AT_CHECK([ovsdb-client transact 'txn'], [0], [stdout], [ignore])
    ])
 
-   AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore],
-     [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-   cat stdout >> dump1
-   AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
-     [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-   cat stdout >> dump2
+   AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
+   OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock > dump2; diff stdout dump2])
 
-   AT_CHECK([diff dump1 dump2], [0], [], [ignore],
-            [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
    OVSDB_SERVER_SHUTDOWN
    OVSDB_SERVER_SHUTDOWN2
    AT_CLEANUP])
@@ -1048,27 +1044,26 @@ m4_define([OVSDB_CHECK_REPLICATION],
    AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
 
    AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
+   on_exit 'test ! -e pid || kill `cat pid`'
 
    AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 --sync-from=unix:db.sock --sync-exclude-tables=mydb:b db2], [0], [ignore], [ignore])
+   on_exit 'test ! -e pid2 || kill `cat pid2`'
 
    m4_foreach([txn], [$3],
-     [AT_CHECK([ovsdb-client transact 'txn'; sleep 2], [0], [stdout], [ignore],
-     [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+     [AT_CHECK([ ovsdb-client transact 'txn' ], [0], [stdout], [ignore])
    ])
 
-   AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore],
-     [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-   cat stdout >> dump1
-   AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
-     [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-   cat stdout >> dump2
+   AT_CHECK([ovsdb-client dump], [0], [stdout], [ignore])
+   cat stdout > dump1
 
-   AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore],
-            [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-   cat stdout >> output
+   OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep one ])
+   AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
+   cat stdout > dump2
 
-   AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore],
-            [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+   AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
+   cat stdout > output
+
+   AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [$4], [ignore])
 
    OVSDB_SERVER_SHUTDOWN
    OVSDB_SERVER_SHUTDOWN2
@@ -1126,8 +1121,10 @@ AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
 
 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
+on_exit 'test ! -e pid || kill `cat pid`'
 
 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
+on_exit 'test ! -e pid2 || kill `cat pid2`'
 
 AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-sync-excluded-tables mydb:b], [0], [ignore], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
 
@@ -1140,18 +1137,16 @@ AT_CHECK([ovsdb-client transact unix:db.sock \
       "table": "b",
       "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore],
  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-sleep 2
 
 AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
  [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-cat stdout >> dump1
-AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
- [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-cat stdout >> dump2
+cat stdout > dump1
+OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
+AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
+cat stdout > dump2
 
-AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore],
-        [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-cat stdout >> output
+AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
+cat stdout > output
 
 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [7,9c7,8
 < _uuid                                name number
@@ -1160,7 +1155,7 @@ AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [7,9c7,8
 ---
 > _uuid name number
 > ----- ---- ------
-], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+])
 
 OVSDB_SERVER_SHUTDOWN
 OVSDB_SERVER_SHUTDOWN2
@@ -1174,31 +1169,28 @@ AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
 
 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
+on_exit 'test ! -e pid || kill `cat pid`'
 
 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 db2], [0], [ignore], [ignore])
+on_exit 'test ! -e pid2 || kill `cat pid2`'
 
-AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-active-ovsdb-server unix:db.sock], [0], [ignore], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/set-active-ovsdb-server unix:db.sock], [0], [stdout], [ignore])
 
-AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0], [ignore], [ignore],
-        [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/connect-active-ovsdb-server], [0], [stdout], [ignore])
 
 AT_CHECK([ovsdb-client transact unix:db.sock \
  '[["mydb",
   {"op": "insert",
    "table": "a",
-   "row": {},
-   "uuid-name": "0"}]]'], [0], [stdout], [ignore],
- [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-sleep 2
+   "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
 
-AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
- [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-cat stdout >> dump1
-AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
- [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-cat stdout >> dump2
+AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
+cat stdout > dump1
+OVS_WAIT_UNTIL([ ovsdb-client dump unix:db2.sock | grep zero ])
+AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
+cat stdout > dump2
 
-AT_CHECK([diff dump1 dump2], [0], [], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+AT_CHECK([diff dump1 dump2], [0], [], [ignore])
 OVSDB_SERVER_SHUTDOWN
 OVSDB_SERVER_SHUTDOWN2
 AT_CLEANUP
@@ -1211,15 +1203,16 @@ AT_CHECK([ovsdb-tool create db1 schema], [0], [stdout], [ignore])
 AT_CHECK([ovsdb-tool create db2 schema], [0], [stdout], [ignore])
 
 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server1.log --pidfile="`pwd`"/pid --remote=punix:db.sock --unixctl="`pwd`"/unixctl db1], [0], [ignore], [ignore])
+on_exit 'test ! -e pid || kill `cat pid`'
 
 AT_CHECK([ovsdb-server --detach --no-chdir --log-file=ovsdb-server2.log --pidfile="`pwd`"/pid2 --remote=punix:db2.sock --unixctl="`pwd`"/unixctl2 --sync-from=unix:db.sock db2], [0], [ignore], [ignore])
+on_exit 'test ! -e pid2 || kill `cat pid2`'
 
 AT_CHECK([ovsdb-client transact unix:db.sock \
 '[["mydb",
   {"op": "insert",
    "table": "a",
-   "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore],
-[test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+   "row": {"number": 0, "name": "zero"}}]]'], [0], [stdout], [ignore])
 
 dnl Make sure the transaction shows up in db2. This also tests the back up server
 dnl can be read.
@@ -1234,27 +1227,23 @@ AT_CHECK([ovsdb-client transact unix:db2.sock \
    [[[{"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"}]]
 ])
 
-AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server], [0], [ignore], [ignore],
-        [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/disconnect-active-ovsdb-server], [0], [ignore], [ignore])
 
 AT_CHECK([ovsdb-client transact unix:db.sock \
 '[["mydb",
   {"op": "insert",
    "table": "b",
-   "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore],
-[test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+   "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
 
-AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore],
- [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-cat stdout >> dump1
+AT_CHECK([ovsdb-client dump unix:db.sock], [0], [stdout], [ignore])
+cat stdout > dump1
 
-AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore],
- [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-cat stdout >> dump2
+sleep 1
+AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout], [ignore])
+cat stdout > dump2
 
-AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore],
-        [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
-cat stdout >> output
+AT_CHECK([diff dump1 dump2], [1], [stdout], [ignore])
+cat stdout > output
 
 AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [7,9c7,8
 < _uuid                                name number
@@ -1265,14 +1254,12 @@ AT_CHECK([${PERL} $srcdir/uuidfilt.pl output], [0], [7,9c7,8
 > ----- ---- ------
 ], [ignore], [test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
 
-
 dnl The backup server now become active, and can accept write transactions.
 AT_CHECK([ovsdb-client transact unix:db2.sock \
 '[["mydb",
   {"op": "insert",
    "table": "b",
-   "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore],
-[test ! -e pid || kill `cat pid`; test ! -e pid2 || kill `cat pid2`])
+   "row": {"number": 1, "name": "one"}}]]'], [0], [stdout], [ignore])
 
 AT_CHECK([ovsdb-client dump unix:db2.sock], [0], [stdout])
 cat stdout > output
-- 
1.9.1




More information about the dev mailing list