Verified Commit 89fe563b authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

FakeAkonadiServer: fix flushing notifications before test ends

The flush is asynchronous so just calling dispatchNotifications() and terminating
the event loop is not good enough, we need to call it before the event loop is
terminated and we must wait for the notifications to be delivered otherwise we
just can't be sure that they also reached the test code.
parent 2c482fd0
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <QBuffer> #include <QBuffer>
#include <QStandardPaths> #include <QStandardPaths>
#include <ctime>
#include <private/protocol_p.h> #include <private/protocol_p.h>
#include <private/scope_p.h> #include <private/scope_p.h>
#include <private/standarddirs_p.h> #include <private/standarddirs_p.h>
...@@ -313,7 +314,17 @@ void FakeAkonadiServer::runTest() ...@@ -313,7 +314,17 @@ void FakeAkonadiServer::runTest()
QVERIFY(mCmdServer->listen(socketFile())); QVERIFY(mCmdServer->listen(socketFile()));
QEventLoop serverLoop; QEventLoop serverLoop;
connect(mClient.get(), &QThread::finished, &serverLoop, &QEventLoop::quit); connect(mClient.get(), &QThread::finished,
this, [this, &serverLoop]() {
disconnect(mClient.get(), &QThread::finished, this, nullptr);
// Flush any pending notifications and wait for them
// before shutting down the event loop
if (mNtfCollector->dispatchNotifications()) {
mNotificationSpy->wait();
}
serverLoop.quit();
});
// Start the client: the client will connect to the server and will // Start the client: the client will connect to the server and will
// start playing the scenario // start playing the scenario
...@@ -323,9 +334,6 @@ void FakeAkonadiServer::runTest() ...@@ -323,9 +334,6 @@ void FakeAkonadiServer::runTest()
serverLoop.exec(); serverLoop.exec();
mCmdServer->close(); mCmdServer->close();
// Flush any pending notifications
mNtfCollector->dispatchNotifications();
} }
QSharedPointer<QSignalSpy> FakeAkonadiServer::notificationSpy() const QSharedPointer<QSignalSpy> FakeAkonadiServer::notificationSpy() const
......
...@@ -595,7 +595,7 @@ void NotificationCollector::dispatchNotification(const Protocol::ChangeNotificat ...@@ -595,7 +595,7 @@ void NotificationCollector::dispatchNotification(const Protocol::ChangeNotificat
} }
} }
void NotificationCollector::dispatchNotifications() bool NotificationCollector::dispatchNotifications()
{ {
if (!mNotifications.isEmpty()) { if (!mNotifications.isEmpty()) {
for (auto &ntf : mNotifications) { for (auto &ntf : mNotifications) {
...@@ -603,7 +603,10 @@ void NotificationCollector::dispatchNotifications() ...@@ -603,7 +603,10 @@ void NotificationCollector::dispatchNotifications()
} }
notify(std::move(mNotifications)); notify(std::move(mNotifications));
clear(); clear();
return true;
} }
return false;
} }
void NotificationCollector::notify(Protocol::ChangeNotificationList msgs) void NotificationCollector::notify(Protocol::ChangeNotificationList msgs)
......
...@@ -209,8 +209,11 @@ public: ...@@ -209,8 +209,11 @@ public:
/** /**
Trigger sending of collected notifications. Trigger sending of collected notifications.
@returns Returns true when any notifications were dispatched, false if there
were no pending notifications.
*/ */
void dispatchNotifications(); bool dispatchNotifications();
private: private:
void itemNotification(Protocol::ItemChangeNotification::Operation op, void itemNotification(Protocol::ItemChangeNotification::Operation op,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment