Skip to content

Commit

Permalink
test: Improve replication unit tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
azhou-nicira committed Sep 1, 2016
1 parent 6ab3dd9 commit 5dd81c2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 70 deletions.
28 changes: 22 additions & 6 deletions tests/ovsdb-replication.at
Original file line number Diff line number Diff line change
Expand Up @@ -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@
Expand All @@ -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@
Expand Down Expand Up @@ -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@
Expand All @@ -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@
Expand Down
115 changes: 51 additions & 64 deletions tests/ovsdb-server.at
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`])

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5dd81c2

Please sign in to comment.