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 @@
#include <QBuffer>
#include <QStandardPaths>
#include <ctime>
#include <private/protocol_p.h>
#include <private/scope_p.h>
#include <private/standarddirs_p.h>
......@@ -313,7 +314,17 @@ void FakeAkonadiServer::runTest()
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()) {
// Start the client: the client will connect to the server and will
// start playing the scenario
......@@ -323,9 +334,6 @@ void FakeAkonadiServer::runTest()
// Flush any pending notifications
QSharedPointer<QSignalSpy> FakeAkonadiServer::notificationSpy() const
......@@ -595,7 +595,7 @@ void NotificationCollector::dispatchNotification(const Protocol::ChangeNotificat
void NotificationCollector::dispatchNotifications()
bool NotificationCollector::dispatchNotifications()
if (!mNotifications.isEmpty()) {
for (auto &ntf : mNotifications) {
......@@ -603,7 +603,10 @@ void NotificationCollector::dispatchNotifications()
return true;
return false;
void NotificationCollector::notify(Protocol::ChangeNotificationList msgs)
......@@ -209,8 +209,11 @@ public:
Trigger sending of collected notifications.
@returns Returns true when any notifications were dispatched, false if there
were no pending notifications.
void dispatchNotifications();
bool dispatchNotifications();
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