summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMatt Newell <newellm@blur.com>2012-03-22 10:42:56 -0700
committerQt by Nokia <qt-info@nokia.com>2012-03-30 23:51:11 +0200
commitaea684506945a12312fc05fb3bb4f549da93f7f5 (patch)
tree5fac9268349e5e8fb4962db5382206c76fb1163f /tests/auto
parent4efd61c3cf3d25db1c60bf5c842837c5b24a05fa (diff)
Fix postgres notification support in the QPSQLDriver.
This patch fixes a critical bug in the qsqlpsql driver where notifications aren't delivered when received. Any blocking libpq function(specifically PQexec) will read all the incoming data from the socket, including any pending notifications. This would cause the socket notifier to never be fired for incoming notifications that are already queued inside libpq. The qsqldriver test case was skipping the postgres notification test because of this bug, now its enabled and passing. In order to fix this bug I made a wrapper function for PQexec in QPSQLDriverPrivate that calls _q_handleNotification via QMetaObject::callMethod QueuedConnection in order to deliver pending notifications when control returns to the event loop. I also added a flag to ensure only one call is made each time the event loop is entered. Change-Id: I19f5297094ae7ae46bfb0717e4fca744d69f7b92 Reviewed-by: Honglei Zhang <honglei.zhang@nokia.com> Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp
index 7acbf816f1..992df6e0b6 100644
--- a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp
+++ b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp
@@ -54,6 +54,8 @@
#include "tst_databases.h"
+Q_DECLARE_METATYPE(QSqlDriver::NotificationSource)
+
QT_FORWARD_DECLARE_CLASS(QSqlDatabase)
struct FieldDef;
@@ -385,6 +387,7 @@ void tst_QSqlDatabase::populateTestTables(QSqlDatabase db)
void tst_QSqlDatabase::initTestCase()
{
+ qRegisterMetaType<QSqlDriver::NotificationSource>("QSqlDriver::NotificationSource");
dbs.open();
for (QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it) {
@@ -2064,21 +2067,17 @@ void tst_QSqlDatabase::eventNotificationPSQL()
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
-#if defined(Q_OS_LINUX)
- QSKIP( "Event support doesn't work on linux");
-#endif
-
QSqlQuery query(db);
QString procedureName = qTableName("posteventProc", __FILE__);
-
QSqlDriver &driver=*(db.driver());
QVERIFY_SQL(driver, subscribeToNotification(procedureName));
- QSignalSpy spy(db.driver(), SIGNAL(notification(const QString&)));
+ QSignalSpy spy(db.driver(), SIGNAL(notification(const QString&,QSqlDriver::NotificationSource)));
query.exec(QString("NOTIFY \"%1\"").arg(procedureName));
QCoreApplication::processEvents();
QCOMPARE(spy.count(), 1);
QList<QVariant> arguments = spy.takeFirst();
QVERIFY(arguments.at(0).toString() == procedureName);
+ QVERIFY(qVariantValue<QSqlDriver::NotificationSource>(arguments.at(1)) == QSqlDriver::SelfSource);
QVERIFY_SQL(driver, unsubscribeFromNotification(procedureName));
}