Autotest: synchronize with the peer before emitting more signals

Several of the unit tests request that the peer emit more than one
signal, but only handle one. The rest of the signals stay queued in the
socket and will be delivered at the next test, causing it to fail often.

This doesn't happen in the tests with the bus. There, we don't receive
the extraneous signals due to AddMatch/ReceiveMatch on each signal
individually and the synchronous nature of the emission (the signals
have already been emitted by the next AddMatch and cannot match it).

Task-number: QTBUG-42145
Change-Id: I743a0553074972042fca46b76db5d9e7b3209620
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
bb10
Thiago Macieira 2014-10-28 19:05:43 -07:00
parent d0ed6dc146
commit 5368e44a86
2 changed files with 38 additions and 1 deletions

View File

@ -75,6 +75,11 @@ public slots:
return m_conn.isConnected();
}
Q_NOREPLY void requestSync(const QString &seq)
{
emit syncReceived(seq);
}
void emitSignal(const QString& interface, const QString& name, const QDBusVariant& parameter)
{
if (interface.endsWith('2'))
@ -126,10 +131,14 @@ public slots:
valueSpy.clear();
}
signals:
Q_SCRIPTABLE void syncReceived(const QString &sequence);
private slots:
void handleConnection(const QDBusConnection& con)
void handleConnection(QDBusConnection con)
{
m_conn = con;
con.registerObject(objectPath, this, QDBusConnection::ExportScriptableSignals);
}
private:

View File

@ -338,6 +338,24 @@ void registerMyObjectPeer(const QString & path, QDBusConnection::RegisterOptions
QDBusMessage reply = QDBusConnection::sessionBus().call(req);
}
void syncPeer()
{
static int counter = 0;
QString reqId = QString::number(++counter);
// wait for the sync signal with the right ID
QEventLoop loop;
QDBusConnection con("peer");
con.connect(serviceName, objectPath, interfaceName, "syncReceived",
QStringList() << reqId, QString(), &loop, SLOT(quit()));
QDBusMessage req = QDBusMessage::createMethodCall(serviceName, objectPath, interfaceName, "requestSync");
req << reqId;
QDBusConnection::sessionBus().send(req);
loop.exec();
}
void emitSignalPeer(const QString &interface, const QString &name, const QVariant &parameter)
{
if (parameter.isValid())
@ -1159,6 +1177,8 @@ void tst_QDBusAbstractAdaptor::signalEmissionsPeer()
// connect all signals and emit only one
{
syncPeer();
QDBusSignalSpy spy;
con.connect(QString(), "/", "local.Interface2", "signal",
&spy, SLOT(slot(QDBusMessage)));
@ -1186,6 +1206,8 @@ void tst_QDBusAbstractAdaptor::signalEmissionsPeer()
// connect one signal and emit them all
{
syncPeer();
QDBusSignalSpy spy;
con.connect(QString(), "/", interface, name, &spy, SLOT(slot(QDBusMessage)));
emitSignalPeer("local.Interface2", "signal", QVariant());
@ -1214,6 +1236,7 @@ void tst_QDBusAbstractAdaptor::sameSignalDifferentPathsPeer()
registerMyObjectPeer("/p1");
registerMyObjectPeer("/p2");
syncPeer();
QDBusSignalSpy spy;
con.connect(QString(), "/p1", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage)));
emitSignalPeer("local.Interface2", QString(), QVariant());
@ -1241,6 +1264,7 @@ void tst_QDBusAbstractAdaptor::sameObjectDifferentPathsPeer()
registerMyObjectPeer("/p1");
registerMyObjectPeer("/p2", 0); // don't export anything
syncPeer();
QDBusSignalSpy spy;
con.connect(QString(), "/p1", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage)));
con.connect(QString(), "/p2", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage)));
@ -1263,6 +1287,7 @@ void tst_QDBusAbstractAdaptor::scriptableSignalOrNotPeer()
registerMyObjectPeer("/p1", QDBusConnection::ExportScriptableSignals);
registerMyObjectPeer("/p2", 0); // don't export anything
syncPeer();
QDBusSignalSpy spy;
con.connect(QString(), "/p1", "local.MyObject", "scriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
con.connect(QString(), "/p2", "local.MyObject", "scriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
@ -1286,6 +1311,7 @@ void tst_QDBusAbstractAdaptor::scriptableSignalOrNotPeer()
registerMyObjectPeer("/p2", QDBusConnection::ExportScriptableSignals
| QDBusConnection::ExportNonScriptableSignals);
syncPeer();
QDBusSignalSpy spy;
con.connect(QString(), "/p1", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
con.connect(QString(), "/p2", "local.MyObject", "nonScriptableSignalVoid", &spy, SLOT(slot(QDBusMessage)));
@ -1338,6 +1364,7 @@ void tst_QDBusAbstractAdaptor::overloadedSignalEmissionPeer()
// connect all signals and emit only one
{
syncPeer();
QDBusSignalSpy spy;
con.connect(QString(), "/", "local.Interface4", "signal", "",
&spy, SLOT(slot(QDBusMessage)));
@ -1358,6 +1385,7 @@ void tst_QDBusAbstractAdaptor::overloadedSignalEmissionPeer()
QFETCH(QString, signature);
// connect one signal and emit them all
{
syncPeer();
QDBusSignalSpy spy;
con.connect(QString(), "/", interface, name, signature, &spy, SLOT(slot(QDBusMessage)));
emitSignalPeer("local.Interface4", "signal", QVariant());