diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2015-01-01 19:56:06 -0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2015-01-06 17:36:58 +0100 |
commit | aa83bacb14dac06eb7226c8c688f37eeecec15d4 (patch) | |
tree | 223ea192ba0b4eb268c352b67e3589907a567411 /tests/auto/dbus/qdbusinterface/qmyserver | |
parent | 01fc82e3574614762d2ce061dd45ce4995c79e7f (diff) |
Autotest: fix a race condition in verifying a peer D-Bus connected
On the unit test side, everything is sequential: we first ask for the
connection, verify that it is connected, then ask the remote side via
the session bus if it is connected. Unfortunately, the remote site may
handle things in a different order: it may handle the incoming function
call to "isConnected" before doing accept(2) on the listening socket.
So, instead, make the local side block until the connection is received
on the other side. On the remote, we don't block, instead we use the
feature of delayed replies.
Change-Id: Ie386938b8b39dd94a9d7e5913668125fb4a3c7da
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'tests/auto/dbus/qdbusinterface/qmyserver')
-rw-r--r-- | tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp b/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp index d3cfaa74b3..8da9068541 100644 --- a/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp +++ b/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp @@ -63,9 +63,17 @@ public slots: return QDBusServer::address(); } - bool isConnected() const + void waitForConnected() { - return m_conn.isConnected(); + if (callPendingReply.type() != QDBusMessage::InvalidMessage) { + sendErrorReply(QDBusError::NotSupported, "One call already pending!"); + return; + } + if (m_conn.isConnected()) + return; + // not connected, we'll reply later + setDelayedReply(true); + callPendingReply = message(); } void emitSignal(const QString &interface, const QString &name, const QString &arg) @@ -123,10 +131,15 @@ private slots: m_conn.registerObject("/", &obj, QDBusConnection::ExportAllProperties | QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllInvokables); + if (callPendingReply.type() != QDBusMessage::InvalidMessage) { + QDBusConnection::sessionBus().send(callPendingReply.createReply()); + callPendingReply = QDBusMessage(); + } } private: QDBusConnection m_conn; + QDBusMessage callPendingReply; MyObject obj; }; |