testing: make testSession3 reliable again, finish server startup change

The "D-Bus testing: don't depend on server output during startup, truely quiet
TEST_DBUS_QUIET" change broke TestFileNotify.testSession3: because the test
started after syncevo-dbus-server obtained the bus name and before the server
could finish its startup (which test-dbus.py previously waited for by waiting
for the server's output), the executable was touched too soon and the server
often didn't notice that it had to shut down.

This inherent race condition can't be fixed, but in reality it should be a lot
rarer (not happening at all?) than in testing. Therefore fix testing by having
test-dbus.py wait for a response from syncevo-dbus-server (which implies that
it is done with its startup) before starting the test.

This actually applies to all three ways of starting syncevo-dbus-server (with
gdb, with and without logging), so now all of them use the same code.
This commit is contained in:
Patrick Ohly 2013-09-02 11:06:10 -07:00
parent 83dcba8486
commit 1a4d9fd06f
1 changed files with 9 additions and 11 deletions

View File

@ -557,10 +557,6 @@ class DBusUtil(Timeout):
gdbinit = []
DBusUtil.pserver = subprocess.Popen([debugger] + gdbinit + ['--args'] + server,
env=env)
while not bus.name_has_owner('org.syncevolution'):
time.sleep(1)
print "\nfound org.syncevolution on session bus, starting test"
else:
if os.environ.get("SYNCEVOLUTION_DEBUG", None):
logfile = None
@ -581,13 +577,14 @@ class DBusUtil(Timeout):
env=env,
stdout=logfile,
stderr=subprocess.STDOUT)
if logfile != None:
while self.isServerRunning() and not bus.name_has_owner('org.syncevolution'):
time.sleep(1)
else:
print "test-dbus.py: giving syncevo-dbus-server time to start"
time.sleep(5)
print "test-dbus.py: starting test"
# Don't use D-Bus auto-activation. Instead wait for our process to show up.
while self.isServerRunning() and not bus.name_has_owner('org.syncevolution'):
time.sleep(1)
# In addition, ensure that it is fully running by calling one method.
dbus.Interface(bus.get_object('org.syncevolution',
'/org/syncevolution/Server'),
'org.syncevolution.Server').GetVersions(timeout=self.dbusTimeout)
# pserver.pid is not necessarily the pid of syncevo-dbus-server.
# It might be the child of the pserver process.
@ -4925,6 +4922,7 @@ class TestFileNotify(unittest.TestCase, DBusUtil):
def modifyServerFile(self):
"""rename server executable to trigger shutdown"""
logging.printf('touching server file %s to trigger shutdown', self.serverexe)
os.rename(self.serverexe, self.serverexe + ".bak")
os.rename(self.serverexe + ".bak", self.serverexe)