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:
parent
36314ae75f
commit
d55db285fc
@ -163,6 +163,7 @@ int main(int argc, char *argv[])
|
||||
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots);
|
||||
|
||||
printf("ready.\n");
|
||||
fflush(stdout);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -118,6 +118,7 @@ int main(int argc, char *argv[])
|
||||
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots);
|
||||
|
||||
printf("ready.\n");
|
||||
fflush(stdout);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -142,6 +142,7 @@ int main(int argc, char *argv[])
|
||||
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots);
|
||||
|
||||
printf("ready.\n");
|
||||
fflush(stdout);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -66,6 +66,7 @@ int main(int argc, char *argv[])
|
||||
con.registerObject(objectPath, &pong, QDBusConnection::ExportAllSlots);
|
||||
|
||||
printf("ready.\n");
|
||||
fflush(stdout);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -51,6 +51,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
ServerObject obj(objectPath, con);
|
||||
printf("ready.\n");
|
||||
fflush(stdout);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user