From: Ben Pfaff Date: Thu, 3 Dec 2009 22:45:16 +0000 (-0800) Subject: ovsdb: Fix race conditions in test suite. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b12e3c41afaeb9faed1e3562954ec78fd595677d;p=openvswitch ovsdb: Fix race conditions in test suite. --- diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at index cf931039..cf9f1ba3 100644 --- a/tests/ovsdb-idl.at +++ b/tests/ovsdb-idl.at @@ -19,7 +19,7 @@ m4_define([OVSDB_CHECK_IDL], AT_KEYWORDS([ovsdb server idl positive $5]) OVS_CHECK_LCOV([ovsdb-tool create db $abs_builddir/idltest.ovsschema], [0], [stdout], [ignore]) - AT_CHECK([ovsdb-server --detach --pidfile=$PWD/server-pid --listen=punix:socket --unixctl=$PWD/unixctl db]) + AT_CHECK([ovsdb-server --detach --pidfile=$PWD/server-pid --listen=punix:socket --unixctl=$PWD/unixctl db], [0], [ignore], [ignore]) m4_if([$2], [], [], [OVS_CHECK_LCOV([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat server-pid`])]) AT_CHECK([test-ovsdb -vjsonrpc -t10 idl unix:socket $3], diff --git a/tests/ovsdb-monitor.at b/tests/ovsdb-monitor.at index e57f41a0..f0b20e15 100644 --- a/tests/ovsdb-monitor.at +++ b/tests/ovsdb-monitor.at @@ -23,15 +23,17 @@ m4_define([OVSDB_CHECK_MONITOR], OVS_CHECK_LCOV([ovsdb-tool create db schema], [0], [stdout], [ignore]) m4_foreach([txn], [$3], [OVS_CHECK_LCOV([ovsdb-tool transact db 'txn'], [0], [ignore], [ignore])]) - AT_CHECK([ovsdb-server --detach --pidfile=$PWD/server-pid --listen=punix:socket --unixctl=$PWD/unixctl db]) - AT_CHECK([ovsdb-client monitor --format=csv unix:socket $4 > output & echo $! > monitor-pid], + AT_CHECK([ovsdb-server --detach --pidfile=$PWD/server-pid --listen=punix:socket --unixctl=$PWD/unixctl db], [0], [ignore], [ignore]) + AT_CHECK([ovsdb-client --detach --pidfile=$PWD/client-pid monitor --format=csv unix:socket $4 > output], [0], [ignore], [ignore], [kill `cat server-pid`]) m4_foreach([txn], [$5], [OVS_CHECK_LCOV([ovsdb-client transact unix:socket 'txn'], [0], - [ignore], [ignore], [kill `cat server-pid monitor-pid`])]) + [ignore], [ignore], [kill `cat server-pid client-pid`])]) + OVS_CHECK_LCOV([ovsdb-client transact unix:socket '[[]]'], [0], + [ignore], [ignore], [kill `cat server-pid client-pid`]) AT_CHECK([ovs-appctl -t $PWD/unixctl -e exit], [0], [ignore], [ignore]) - wait - AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$6]) + OVS_WAIT_UNTIL([test ! -e server-pid && test ! -e client-pid && exit 0]) + AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$6], [ignore]) AT_CLEANUP]) OVSDB_CHECK_MONITOR([monitor insert into empty table], diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at index 359f7e2e..98aeb4a8 100644 --- a/tests/ovsdb-server.at +++ b/tests/ovsdb-server.at @@ -20,13 +20,13 @@ m4_define([OVSDB_CHECK_EXECUTION], AT_DATA([schema], [$2 ]) OVS_CHECK_LCOV([ovsdb-tool create db schema], [0], [stdout], [ignore]) - AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --listen=punix:socket --unixctl=$PWD/unixctl db]) + AT_CHECK([ovsdb-server --detach --pidfile=$PWD/pid --listen=punix:socket --unixctl=$PWD/unixctl db], [0], [ignore], [ignore]) m4_foreach([txn], [$3], [OVS_CHECK_LCOV([ovsdb-client transact unix:socket 'txn'], [0], [stdout], [ignore], [test ! -e pid || kill `cat pid`]) cat stdout >> output ]) - AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [], + AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$4], [ignore], [test ! -e pid || kill `cat pid`]) test ! -e pid || kill `cat pid` AT_CLEANUP]) diff --git a/tests/testsuite.at b/tests/testsuite.at index d5eadc21..ceded7e1 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -18,6 +18,20 @@ AT_TESTED([ovs-vswitchd]) AT_TESTED([ovs-vsctl]) AT_TESTED([perl]) +m4_define([OVS_WAIT_UNTIL], + [AT_CHECK( + [# First try a quick sleep, so that the test completes very quickly + # in the normal case. POSIX doesn't require fractional times to + # work, so this might not work. + sleep 0.1 + $1 + # Then wait up to 10 seconds. + for d in 0 1 2 3 4 5 6 7 8 9; do + sleep 1 + $1 + done + exit 1], [0], [ignore], [ignore])]) + m4_include([tests/lcov-pre.at]) m4_include([tests/library.at]) m4_include([tests/dir_name.at])