summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2010-11-27 23:00:12 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2010-11-27 23:00:12 (GMT)
commit37766cd0781218598daffeaa7fa9d1707ec14b38 (patch)
tree28f19a5eda972a7d8a4f1425983e0273716891ec /tests
parent5e0c4463c8dc8857e9f64a1bdde9a94cd8c39c4d (diff)
parent220d13f0e83f9a70e69d95cb78711fec309e83cc (diff)
downloadQt-37766cd0781218598daffeaa7fa9d1707ec14b38.zip
Qt-37766cd0781218598daffeaa7fa9d1707ec14b38.tar.gz
Qt-37766cd0781218598daffeaa7fa9d1707ec14b38.tar.bz2
Merge branch '4.7-upstream' into 4.7-water
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qdbusconnection/tst_qdbusconnection.cpp69
-rw-r--r--tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp9
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp1
-rw-r--r--tests/auto/qsettings/tst_qsettings.cpp13
4 files changed, 76 insertions, 16 deletions
diff --git a/tests/auto/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/qdbusconnection/tst_qdbusconnection.cpp
index 599abbd..4494d6f 100644
--- a/tests/auto/qdbusconnection/tst_qdbusconnection.cpp
+++ b/tests/auto/qdbusconnection/tst_qdbusconnection.cpp
@@ -106,6 +106,8 @@ private slots:
void slotsWithLessParameters();
void nestedCallWithCallback();
+ void serviceRegistrationRaceCondition();
+
public:
QString serviceName() const { return "com.trolltech.Qt.Autotests.QDBusConnection"; }
bool callMethod(const QDBusConnection &conn, const QString &path);
@@ -647,6 +649,73 @@ void tst_QDBusConnection::nestedCallWithCallback()
QCOMPARE(signalsReceived, 1);
}
+class RaceConditionSignalWaiter : public QObject
+{
+ Q_OBJECT
+public:
+ int count;
+ RaceConditionSignalWaiter() : count (0) {}
+ virtual ~RaceConditionSignalWaiter() {}
+
+public slots:
+ void countUp() { ++count; emit done(); }
+signals:
+ void done();
+};
+
+void tst_QDBusConnection::serviceRegistrationRaceCondition()
+{
+ // There was a race condition in the updating of list of name owners in
+ // QtDBus. When the user connects to a signal coming from a given
+ // service, we must listen for NameOwnerChanged signals relevant to that
+ // name and update when the owner changes. However, it's possible that we
+ // receive in one chunk from the server both the NameOwnerChanged signal
+ // about the service and the signal we're interested in. Since QtDBus
+ // posts events in order to handle the incoming signals, the update
+ // happens too late.
+
+ const QString connectionName = "testConnectionName";
+ const QString serviceName = "org.example.SecondaryName";
+
+ QDBusConnection session = QDBusConnection::sessionBus();
+ QVERIFY(!session.interface()->isServiceRegistered(serviceName));
+
+ // connect to the signal:
+ RaceConditionSignalWaiter recv;
+ session.connect(serviceName, "/", "com.trolltech.TestCase", "oneSignal", &recv, SLOT(countUp()));
+
+ // create a secondary connection and register a name
+ QDBusConnection connection = QDBusConnection::connectToBus(QDBusConnection::SessionBus, connectionName);
+ QDBusConnection::disconnectFromBus(connectionName); // disconnection happens when "connection" goes out of scope
+ QVERIFY(connection.isConnected());
+ QVERIFY(connection.registerService(serviceName));
+
+ // send a signal
+ QDBusMessage msg = QDBusMessage::createSignal("/", "com.trolltech.TestCase", "oneSignal");
+ connection.send(msg);
+
+ // make a blocking call just to be sure that the buffer was flushed
+ msg = QDBusMessage::createMethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus",
+ "NameHasOwner");
+ msg << connectionName;
+ connection.call(msg); // ignore result
+
+ // Now here's the race condition (more info on task QTBUG-15651):
+ // the bus has most likely queued three signals for us to work on:
+ // 1) NameOwnerChanged for the connection we created above
+ // 2) NameOwnerChanged for the service we registered above
+ // 3) The "oneSignal" signal we sent
+ //
+ // We'll most likely receive all three in one go from the server. We must
+ // update the owner of serviceName before we start processing the
+ // "oneSignal" signal.
+
+ QTestEventLoop::instance().connect(&recv, SIGNAL(done()), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(1);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QCOMPARE(recv.count, 1);
+}
+
QString MyObject::path;
QTEST_MAIN(tst_QDBusConnection)
diff --git a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
index a26e34d..1feaced 100644
--- a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
+++ b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
@@ -135,14 +135,11 @@ void tst_QFileSystemWatcher::basicTest()
// create watcher, forcing it to use a specific backend
QFileSystemWatcher watcher;
watcher.setObjectName(QLatin1String("_qt_autotest_force_engine_") + backend);
+ watcher.removePath(testFile.fileName());
watcher.addPath(testFile.fileName());
QSignalSpy changedSpy(&watcher, SIGNAL(fileChanged(const QString &)));
QEventLoop eventLoop;
- connect(&watcher,
- SIGNAL(fileChanged(const QString &)),
- &eventLoop,
- SLOT(quit()));
QTimer timer;
connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
@@ -278,10 +275,6 @@ void tst_QFileSystemWatcher::watchDirectory()
QSignalSpy changedSpy(&watcher, SIGNAL(directoryChanged(const QString &)));
QEventLoop eventLoop;
- connect(&watcher,
- SIGNAL(directoryChanged(const QString &)),
- &eventLoop,
- SLOT(quit()));
QTimer timer;
connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 90416f2..9cf61f9 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -4490,6 +4490,7 @@ void tst_QNetworkReply::httpProxyCommandsSynchronous()
QVERIFY(reply->isFinished()); // synchronous
manager.setProxy(QNetworkProxy());
serverThread.quit();
+ serverThread.wait(3000);
//qDebug() << reply->error() << reply->errorString();
diff --git a/tests/auto/qsettings/tst_qsettings.cpp b/tests/auto/qsettings/tst_qsettings.cpp
index 0395eff..0813e28 100644
--- a/tests/auto/qsettings/tst_qsettings.cpp
+++ b/tests/auto/qsettings/tst_qsettings.cpp
@@ -51,6 +51,7 @@
#include <QtCore/QMetaType>
#include <QtCore/QtDebug>
#include <QtCore/QString>
+#include "../../shared/util.h"
#if !defined(Q_OS_SYMBIAN)
# include <cctype>
@@ -1726,26 +1727,22 @@ void tst_QSettings::testUpdateRequestEvent()
settings1.setValue("key1", 1);
QVERIFY(QFileInfo("foo").size() == 0);
- qApp->processEvents();
- QVERIFY(QFileInfo("foo").size() > 0);
+ QTRY_VERIFY(QFileInfo("foo").size() > 0);
settings1.remove("key1");
QVERIFY(QFileInfo("foo").size() > 0);
- qApp->processEvents();
- QVERIFY(QFileInfo("foo").size() == 0);
+ QTRY_VERIFY(QFileInfo("foo").size() == 0);
settings1.setValue("key2", 2);
QVERIFY(QFileInfo("foo").size() == 0);
- qApp->processEvents();
- QVERIFY(QFileInfo("foo").size() > 0);
+ QTRY_VERIFY(QFileInfo("foo").size() > 0);
settings1.clear();
QVERIFY(QFileInfo("foo").size() > 0);
- qApp->processEvents();
- QVERIFY(QFileInfo("foo").size() == 0);
+ QTRY_VERIFY(QFileInfo("foo").size() == 0);
}
const int NumIterations = 5;