Autotest: Fix a race condition in launching the QtDBus sub-processes

Wait for the subprocess to print "ready" before assuming that it is
ready to receive calls. waitForStarted() will return as soon as the
child is running, but it may not have registered on D-Bus yet.

This also solves the synchronization problem more elegantly than how
tst_qdbusmarshall.cpp was trying to do it.

Change-Id: I548dfba2677cc5a34ba50f4310c4d5baa98093b2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Thiago Macieira 2014-12-11 17:50:01 -08:00
parent 36314ae75f
commit d55db285fc
10 changed files with 11 additions and 14 deletions

View File

@ -163,6 +163,7 @@ int main(int argc, char *argv[])
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots);
printf("ready.\n");
fflush(stdout);
return app.exec();
}

View File

@ -498,6 +498,7 @@ void tst_QDBusAbstractAdaptor::initTestCase()
#endif
proc.start(QFINDTESTDATA("qmyserver/qmyserver" EXE));
QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
QVERIFY(proc.waitForReadyRead());
WaitForQMyServer w;
QVERIFY(w.ok());

View File

@ -118,6 +118,7 @@ int main(int argc, char *argv[])
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots);
printf("ready.\n");
fflush(stdout);
return app.exec();
}

View File

@ -238,6 +238,7 @@ void tst_QDBusAbstractInterface::initTestCase()
#endif
proc.start(QFINDTESTDATA("qpinger/qpinger" EXE));
QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
QVERIFY(proc.waitForReadyRead());
// verify service is now registered
QTRY_VERIFY(con.interface()->isServiceRegistered(serviceName));

View File

@ -142,6 +142,7 @@ int main(int argc, char *argv[])
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots);
printf("ready.\n");
fflush(stdout);
return app.exec();
}

View File

@ -273,6 +273,7 @@ void tst_QDBusInterface::initTestCase()
#endif
proc.start(QFINDTESTDATA("qmyserver/qmyserver" EXE));
QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
QVERIFY(proc.waitForReadyRead());
WaitForQMyServer w;
QVERIFY(w.ok());

View File

@ -66,6 +66,7 @@ int main(int argc, char *argv[])
con.registerObject(objectPath, &pong, QDBusConnection::ExportAllSlots);
printf("ready.\n");
fflush(stdout);
return app.exec();
}

View File

@ -137,20 +137,8 @@ void tst_QDBusMarshall::initTestCase()
# define EXE ""
#endif
proc.start(QFINDTESTDATA("qpong/qpong" EXE));
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName)) {
QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
QVERIFY(con.isConnected());
con.connect("org.freedesktop.DBus", QString(), "org.freedesktop.DBus", "NameOwnerChanged",
QStringList() << serviceName << QString(""), QString(),
&QTestEventLoop::instance(), SLOT(exitLoop()));
QTestEventLoop::instance().enterLoop(2);
QVERIFY(!QTestEventLoop::instance().timeout());
QVERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName));
con.disconnect("org.freedesktop.DBus", QString(), "org.freedesktop.DBus", "NameOwnerChanged",
QStringList() << serviceName << QString(""), QString(),
&QTestEventLoop::instance(), SLOT(exitLoop()));
}
QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
QVERIFY(proc.waitForReadyRead());
}
void tst_QDBusMarshall::cleanupTestCase()

View File

@ -51,6 +51,7 @@ int main(int argc, char *argv[])
ServerObject obj(objectPath, con);
printf("ready.\n");
fflush(stdout);
return app.exec();
}

View File

@ -86,6 +86,7 @@ void tst_QDBusPerformance::initTestCase()
#endif
proc.start(QFINDTESTDATA("server/server" EXE));
QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
QVERIFY(proc.waitForReadyRead());
QTestEventLoop::instance().enterLoop(5);
QVERIFY(con.interface()->isServiceRegistered(serviceName));