From aa83bacb14dac06eb7226c8c688f37eeecec15d4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 1 Jan 2015 19:56:06 -0200 Subject: 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 --- tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'tests/auto/dbus/qdbusinterface/qmyserver') 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; }; -- cgit v1.2.3