Verified Commit 2c482fd0 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Make isolated tests more robust by waiting for monitorReady()

Whenever Monitor is used in tests, we must wait for it to emit monitorReady()
before proceeding with the test otherwise there's chance that the Akonadi
server will emit the event before the Monitor started listening (because
the Monitor registers itself to the server asynchronously) and thus
we would miss the signal.
parent d3cb19a6
......@@ -29,6 +29,7 @@
#include <QSettings>
#include <qtest_akonadi.h>
#include <qtestsupport_core.h>
using namespace Akonadi;
......@@ -74,18 +75,15 @@ private Q_SLOTS:
QFETCH(QStringList, actions);
QString lastAction;
ChangeRecorder *rec = createChangeRecorder();
AkonadiTest::akWaitForSignal(rec, SIGNAL(monitorReady()), 1000);
auto rec = createChangeRecorder();
QVERIFY(rec->isEmpty());
for (const QString &action : qAsConst(actions)) {
qDebug() << action;
if (action == QLatin1String("rn")) {
replayNextAndExpectNothing(rec);
replayNextAndExpectNothing(rec.get());
} else if (action == QLatin1String("reload")) {
// Check saving and loading from disk
delete rec;
rec = createChangeRecorder();
AkonadiTest::akWaitForSignal(rec, SIGNAL(monitorReady()), 1000);
} else if (action.at(0) == QLatin1Char('c')) {
// c1 = "trigger change on item 1"
const int id = action.midRef(1).toInt();
......@@ -93,7 +91,7 @@ private Q_SLOTS:
triggerChange(id);
if (action != lastAction) {
// enter event loop and wait for change notifications from the server
QVERIFY(AkonadiTest::akWaitForSignal(rec, SIGNAL(changesAdded()), 1000));
QVERIFY(AkonadiTest::akWaitForSignal(rec.get(), &ChangeRecorder::changesAdded, 1000));
}
} else if (action.at(0) == QLatin1Char('d')) {
// d1 = "delete item 1"
......@@ -105,14 +103,13 @@ private Q_SLOTS:
// r1 = "replayNext and expect to get itemChanged(1)"
const int id = action.midRef(1).toInt();
Q_ASSERT(id);
replayNextAndProcess(rec, id);
replayNextAndProcess(rec.get(), id);
} else {
QVERIFY2(false, qPrintable(QStringLiteral("Unsupported: ") + action));
}
lastAction = action;
}
QVERIFY(rec->isEmpty());
delete rec;
}
private:
......@@ -143,7 +140,7 @@ private:
rec->replayNext();
if (itemChangedSpy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(rec, SIGNAL(itemChanged(Akonadi::Item,QSet<QByteArray>)), 1000));
QVERIFY(AkonadiTest::akWaitForSignal(rec, &Monitor::itemChanged, 1000));
}
QCOMPARE(itemChangedSpy.count(), 1);
QCOMPARE(itemChangedSpy.at(0).at(0).value<Akonadi::Item>().id(), expectedUid);
......@@ -166,9 +163,9 @@ private:
QCOMPARE(nothingSpy.count(), 1);
}
ChangeRecorder *createChangeRecorder() const
std::unique_ptr<ChangeRecorder> createChangeRecorder() const
{
ChangeRecorder *rec = new ChangeRecorder();
auto rec = std::make_unique<ChangeRecorder>();
rec->setConfig(settings);
rec->setAllMonitored();
rec->itemFetchScope().fetchFullPayload();
......@@ -176,8 +173,14 @@ private:
rec->itemFetchScope().setCacheOnly(true);
// Ensure we listen to a signal, otherwise MonitorPrivate::isLazilyIgnored will ignore notifications
QSignalSpy *spy = new QSignalSpy(rec, &Monitor::itemChanged);
spy->setParent(rec);
QSignalSpy *spy = new QSignalSpy(rec.get(), &Monitor::itemChanged);
spy->setParent(rec.get());
QSignalSpy readySpy(rec.get(), &Monitor::monitorReady);
if (!readySpy.wait()) {
QTest::qFail("Failed to wait for Monitor", __FILE__, __LINE__);
return nullptr;
}
return rec;
}
......
......@@ -177,6 +177,7 @@ void EtmPopulationTest::testMonitoringCollectionsPreset()
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
changeRecorder->setCollectionMonitored(col1, true);
changeRecorder->setCollectionMonitored(col2, true);
AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady);
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation);
model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive);
......@@ -197,6 +198,7 @@ void EtmPopulationTest::testMonitoringCollectionsPreset()
void EtmPopulationTest::testMonitoringCollections()
{
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady);
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation);
model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive);
......@@ -222,6 +224,7 @@ void EtmPopulationTest::testFullPopulation()
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
// changeRecorder->setCollectionMonitored(Akonadi::Collection::root());
changeRecorder->setAllMonitored(true);
AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady);
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation);
model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive);
......@@ -244,6 +247,7 @@ void EtmPopulationTest::testAddMonitoringCollections()
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
changeRecorder->setCollectionMonitored(col1, true);
changeRecorder->setCollectionMonitored(col2, true);
AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady);
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation);
model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive);
......@@ -272,6 +276,7 @@ void EtmPopulationTest::testRemoveMonitoringCollections()
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
changeRecorder->setCollectionMonitored(col1, true);
changeRecorder->setCollectionMonitored(col2, true);
AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady);
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation);
model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive);
......@@ -301,6 +306,7 @@ void EtmPopulationTest::testDisplayFilter()
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
InspectableETM *model = new InspectableETM(changeRecorder, this);
AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady);
model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation);
model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive);
model->setListFilter(Akonadi::CollectionFetchScope::Display);
......@@ -327,6 +333,7 @@ void EtmPopulationTest::testLoadingOfHiddenCollection()
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
changeRecorder->setMimeTypeMonitored(QStringLiteral("application/test"), true);
AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady);
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(EntityTreeModel::ImmediatePopulation);
model->setCollectionFetchStrategy(EntityTreeModel::FetchCollectionsRecursive);
......
......@@ -101,6 +101,7 @@ InspectableETM *FavoriteProxyTest::createETM()
{
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
changeRecorder->setCollectionMonitored(Collection::root());
AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady);
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(Akonadi::EntityTreeModel::LazyPopulation);
return model;
......
......@@ -85,8 +85,7 @@ private Q_SLOTS:
monitor.itemFetchScope().setAncestorRetrieval(ItemFetchScope::Parent);
monitor.itemFetchScope().setFetchRemoteIdentification(true);
QSignalSpy moveSpy(&monitor, &Monitor::itemsMoved);
QSignalSpy readySpy(&monitor, &Monitor::monitorReady);
readySpy.wait();
AkonadiTest::akWaitForSignal(&monitor, &Monitor::monitorReady);
ResourceSelectJob *select = new ResourceSelectJob(QStringLiteral("akonadi_knut_resource_0"));
AKVERIFYEXEC(select); // for rid based moves
......
......@@ -29,6 +29,8 @@
#include <itemfetchscope.h>
#include <itemsync.h>
#include <itemcreatejob.h>
#include <memory>
#include <qtestcase.h>
#include <resourceselectjob_p.h>
#include <KRandom>
......@@ -90,6 +92,18 @@ private:
return item;
}
std::unique_ptr<Monitor> createCollectionMonitor(const Collection &col)
{
auto monitor = std::make_unique<Monitor>();
monitor->setCollectionMonitored(col);
if (!AkonadiTest::akWaitForSignal(monitor.get(), &Monitor::monitorReady)) {
QTest::qFail("Failed to wait for monitor", __FILE__, __LINE__);
return nullptr;
}
return monitor;
}
private Q_SLOTS:
void initTestCase()
{
......@@ -156,14 +170,10 @@ private Q_SLOTS:
Item::List origItems = fetchItems(col);
QCOMPARE(origItems.size(), 15);
Akonadi::Monitor monitor;
monitor.setCollectionMonitored(col);
QSignalSpy deletedSpy(&monitor, &Monitor::itemRemoved);
QVERIFY(deletedSpy.isValid());
QSignalSpy addedSpy(&monitor, &Monitor::itemAdded);
QVERIFY(addedSpy.isValid());
QSignalSpy changedSpy(&monitor, &Monitor::itemChanged);
QVERIFY(changedSpy.isValid());
auto monitor = createCollectionMonitor(col);
QSignalSpy deletedSpy(monitor.get(), &Monitor::itemRemoved);
QSignalSpy addedSpy(monitor.get(), &Monitor::itemAdded);
QSignalSpy changedSpy(monitor.get(), &Monitor::itemChanged);
ItemSync *syncer = new ItemSync(col);
QSignalSpy transactionSpy(syncer, &ItemSync::transactionCommitted);
......@@ -224,14 +234,10 @@ private Q_SLOTS:
Item::List origItems = fetchItems(col);
QCOMPARE(origItems.size(), 15);
Akonadi::Monitor monitor;
monitor.setCollectionMonitored(col);
QSignalSpy deletedSpy(&monitor, &Monitor::itemRemoved);
QVERIFY(deletedSpy.isValid());
QSignalSpy addedSpy(&monitor, &Monitor::itemAdded);
QVERIFY(addedSpy.isValid());
QSignalSpy changedSpy(&monitor, &Monitor::itemChanged);
QVERIFY(changedSpy.isValid());
auto monitor = createCollectionMonitor(col);
QSignalSpy deletedSpy(monitor.get(), &Monitor::itemRemoved);
QSignalSpy addedSpy(monitor.get(), &Monitor::itemAdded);
QSignalSpy changedSpy(monitor.get(), &Monitor::itemChanged);
{
ItemSync *syncer = new ItemSync(col);
......@@ -297,14 +303,10 @@ private Q_SLOTS:
QVERIFY(col.isValid());
Item::List origItems = fetchItems(col);
Akonadi::Monitor monitor;
monitor.setCollectionMonitored(col);
QSignalSpy deletedSpy(&monitor, &Monitor::itemRemoved);
QVERIFY(deletedSpy.isValid());
QSignalSpy addedSpy(&monitor, &Monitor::itemAdded);
QVERIFY(addedSpy.isValid());
QSignalSpy changedSpy(&monitor, &Monitor::itemChanged);
QVERIFY(changedSpy.isValid());
auto monitor = createCollectionMonitor(col);
QSignalSpy deletedSpy(monitor.get(), &Monitor::itemRemoved);
QSignalSpy addedSpy(monitor.get(), &Monitor::itemAdded);
QSignalSpy changedSpy(monitor.get(), &Monitor::itemChanged);
ItemSync *syncer = new ItemSync(col);
syncer->setTransactionMode(ItemSync::SingleTransaction);
......@@ -351,14 +353,10 @@ private Q_SLOTS:
QVERIFY(col.isValid());
Item::List origItems = fetchItems(col);
Akonadi::Monitor monitor;
monitor.setCollectionMonitored(col);
QSignalSpy deletedSpy(&monitor, &Monitor::itemRemoved);
QVERIFY(deletedSpy.isValid());
QSignalSpy addedSpy(&monitor, &Monitor::itemAdded);
QVERIFY(addedSpy.isValid());
QSignalSpy changedSpy(&monitor, &Monitor::itemChanged);
QVERIFY(changedSpy.isValid());
auto monitor = createCollectionMonitor(col);
QSignalSpy deletedSpy(monitor.get(), &Monitor::itemRemoved);
QSignalSpy addedSpy(monitor.get(), &Monitor::itemAdded);
QSignalSpy changedSpy(monitor.get(), &Monitor::itemChanged);
ItemSync *syncer = new ItemSync(col);
syncer->setTransactionMode(ItemSync::SingleTransaction);
......@@ -384,14 +382,10 @@ private Q_SLOTS:
QVERIFY(col.isValid());
Item::List origItems = fetchItems(col);
Akonadi::Monitor monitor;
monitor.setCollectionMonitored(col);
QSignalSpy deletedSpy(&monitor, &Monitor::itemRemoved);
QVERIFY(deletedSpy.isValid());
QSignalSpy addedSpy(&monitor, &Monitor::itemAdded);
QVERIFY(addedSpy.isValid());
QSignalSpy changedSpy(&monitor, &Monitor::itemChanged);
QVERIFY(changedSpy.isValid());
auto monitor = createCollectionMonitor(col);
QSignalSpy deletedSpy(monitor.get(), &Monitor::itemRemoved);
QSignalSpy addedSpy(monitor.get(), &Monitor::itemAdded);
QSignalSpy changedSpy(monitor.get(), &Monitor::itemChanged);
ItemSync *syncer = new ItemSync(col);
QSignalSpy transactionSpy(syncer, &ItemSync::transactionCommitted);
......@@ -606,14 +600,10 @@ private Q_SLOTS:
Item dupe = duplicateItem(origItems.at(0), col);
origItems = fetchItems(col);
Akonadi::Monitor monitor;
monitor.setCollectionMonitored(col);
QSignalSpy deletedSpy(&monitor, &Monitor::itemRemoved);
QVERIFY(deletedSpy.isValid());
QSignalSpy addedSpy(&monitor, &Monitor::itemAdded);
QVERIFY(addedSpy.isValid());
QSignalSpy changedSpy(&monitor, &Monitor::itemChanged);
QVERIFY(changedSpy.isValid());
auto monitor = createCollectionMonitor(col);
QSignalSpy deletedSpy(monitor.get(), &Monitor::itemRemoved);
QSignalSpy addedSpy(monitor.get(), &Monitor::itemAdded);
QSignalSpy changedSpy(monitor.get(), &Monitor::itemChanged);
ItemSync *syncer = new ItemSync(col);
syncer->setTransactionMode(ItemSync::SingleTransaction);
......@@ -641,10 +631,8 @@ private Q_SLOTS:
const Collection col = Collection(collectionIdFromPath(QStringLiteral("res2/foo2")));
QVERIFY(col.isValid());
Akonadi::Monitor monitor;
monitor.setCollectionMonitored(col);
QSignalSpy addedSpy(&monitor, &Monitor::itemAdded);
QVERIFY(addedSpy.isValid());
auto monitor = createCollectionMonitor(col);
QSignalSpy addedSpy(monitor.get(), &Monitor::itemAdded);
const int itemCount = 1000;
createItems(col, itemCount);
......@@ -654,10 +642,8 @@ private Q_SLOTS:
const Item::List origItems = fetchItems(col);
QCOMPARE(origItems.size(), itemCount);
QSignalSpy deletedSpy(&monitor, &Monitor::itemRemoved);
QVERIFY(deletedSpy.isValid());
QSignalSpy changedSpy(&monitor, &Monitor::itemChanged);
QVERIFY(changedSpy.isValid());
QSignalSpy deletedSpy(monitor.get(), &Monitor::itemRemoved);
QSignalSpy changedSpy(monitor.get(), &Monitor::itemChanged);
QBENCHMARK {
ItemSync *syncer = new ItemSync(col);
......
......@@ -170,6 +170,7 @@ void LazyPopulationTest::testItemAdded()
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
changeRecorder->setCollectionMonitored(Collection::root());
QVERIFY(AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady));
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(Akonadi::EntityTreeModel::LazyPopulation);
......@@ -255,6 +256,7 @@ void LazyPopulationTest::testItemAddedBeforeFetch()
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
changeRecorder->setCollectionMonitored(Collection::root());
QVERIFY(AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady));
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(Akonadi::EntityTreeModel::LazyPopulation);
......@@ -316,9 +318,11 @@ void LazyPopulationTest::testPurgeEmptyCollection()
//Monitor without referencing so we get all signals
Monitor *monitor = new Monitor(this);
monitor->setCollectionMonitored(Collection::root());
QVERIFY(AkonadiTest::akWaitForSignal(monitor, &Monitor::monitorReady));
ChangeRecorder *changeRecorder = new ChangeRecorder(this);
changeRecorder->setCollectionMonitored(Collection::root());
QVERIFY(AkonadiTest::akWaitForSignal(changeRecorder, &Monitor::monitorReady));
InspectableETM *model = new InspectableETM(changeRecorder, this);
model->setItemPopulationStrategy(Akonadi::EntityTreeModel::LazyPopulation);
......
......@@ -70,16 +70,15 @@ private Q_SLOTS:
QVERIFY(item.hasPayload<QByteArray>());
}
Monitor *monitor = new Monitor(this);
monitor->setCollectionMonitored(col);
monitor->itemFetchScope().fetchFullPayload();
QSignalSpy monitorSpy(monitor, &Monitor::monitorReady);
QVERIFY(monitorSpy.wait());
Monitor monitor;
monitor.setCollectionMonitored(col);
monitor.itemFetchScope().fetchFullPayload();
AkonadiTest::akWaitForSignal(&monitor, &Monitor::monitorReady);
qRegisterMetaType<Akonadi::Collection>();
qRegisterMetaType<Akonadi::Item>();
QSignalSpy lspy(monitor, &Monitor::itemLinked);
QSignalSpy uspy(monitor, &Monitor::itemUnlinked);
QSignalSpy lspy(&monitor, &Monitor::itemLinked);
QSignalSpy uspy(&monitor, &Monitor::itemUnlinked);
QVERIFY(lspy.isValid());
QVERIFY(uspy.isValid());
......
......@@ -83,8 +83,7 @@ private Q_SLOTS:
Monitor dummyMonitor;
MonitorPrivate m(0, &dummyMonitor);
m.monitorAll = true;
QSignalSpy spy(&dummyMonitor, SIGNAL(itemAdded(Akonadi::Item,Akonadi::Collection)));
QVERIFY(spy.isValid());
QSignalSpy spy(&dummyMonitor, &Monitor::itemAdded);
Protocol::ChangeNotification msg;
msg.addEntity(1);
......
......@@ -74,11 +74,13 @@ void MonitorTest::testMonitor()
{
QFETCH(bool, fetchCol);
Monitor *monitor = new Monitor(this);
monitor->setCollectionMonitored(Collection::root());
monitor->fetchCollection(fetchCol);
monitor->itemFetchScope().fetchFullPayload();
monitor->itemFetchScope().setCacheOnly(true);
Monitor monitor;
monitor.setCollectionMonitored(Collection::root());
monitor.fetchCollection(fetchCol);
monitor.itemFetchScope().fetchFullPayload();
monitor.itemFetchScope().setCacheOnly(true);
QVERIFY(AkonadiTest::akWaitForSignal(&monitor, &Monitor::monitorReady));
// monitor signals
qRegisterMetaType<Akonadi::Collection>();
......@@ -107,17 +109,17 @@ void MonitorTest::testMonitor()
qRegisterMetaType<Akonadi::Item>();
qRegisterMetaType<Akonadi::CollectionStatistics>();
qRegisterMetaType<QSet<QByteArray> >();
QSignalSpy caddspy(monitor, &Monitor::collectionAdded);
QSignalSpy cmodspy(monitor, SIGNAL(collectionChanged(Akonadi::Collection,QSet<QByteArray>)));
QSignalSpy cmvspy(monitor, &Monitor::collectionMoved);
QSignalSpy crmspy(monitor, &Monitor::collectionRemoved);
QSignalSpy cstatspy(monitor, &Monitor::collectionStatisticsChanged);
QSignalSpy cSubscribedSpy(monitor, &Monitor::collectionSubscribed);
QSignalSpy cUnsubscribedSpy(monitor, &Monitor::collectionUnsubscribed);
QSignalSpy iaddspy(monitor, &Monitor::itemAdded);
QSignalSpy imodspy(monitor, &Monitor::itemChanged);
QSignalSpy imvspy(monitor, &Monitor::itemMoved);
QSignalSpy irmspy(monitor, &Monitor::itemRemoved);
QSignalSpy caddspy(&monitor, &Monitor::collectionAdded);
QSignalSpy cmodspy(&monitor, SIGNAL(collectionChanged(Akonadi::Collection,QSet<QByteArray>)));
QSignalSpy cmvspy(&monitor, &Monitor::collectionMoved);
QSignalSpy crmspy(&monitor, &Monitor::collectionRemoved);
QSignalSpy cstatspy(&monitor, &Monitor::collectionStatisticsChanged);
QSignalSpy cSubscribedSpy(&monitor, &Monitor::collectionSubscribed);
QSignalSpy cUnsubscribedSpy(&monitor, &Monitor::collectionUnsubscribed);
QSignalSpy iaddspy(&monitor, &Monitor::itemAdded);
QSignalSpy imodspy(&monitor, &Monitor::itemChanged);
QSignalSpy imvspy(&monitor, &Monitor::itemMoved);
QSignalSpy irmspy(&monitor, &Monitor::itemRemoved);
QVERIFY(caddspy.isValid());
QVERIFY(cmodspy.isValid());
......@@ -139,11 +141,8 @@ void MonitorTest::testMonitor()
AKVERIFYEXEC(create);
monitorCol = create->collection();
QVERIFY(monitorCol.isValid());
if (caddspy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionAdded(Akonadi::Collection,Akonadi::Collection)), 6000));
}
QCOMPARE(caddspy.count(), 1);
QTRY_COMPARE(caddspy.count(), 1);
QList<QVariant> arg = caddspy.takeFirst();
Collection col = arg.at(0).value<Collection>();
QCOMPARE(col, monitorCol);
......@@ -171,14 +170,8 @@ void MonitorTest::testMonitor()
AKVERIFYEXEC(append);
Item monitorRef = append->item();
QVERIFY(monitorRef.isValid());
if (cstatspy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)), 1000));
}
for (int i = 0; i < cstatspy.count(); i++) {
qDebug() << "CSTAT" << cstatspy[i][0].toLongLong() << cstatspy[i][1].value<Akonadi::CollectionStatistics>().count();
}
QCOMPARE(cstatspy.count(), 1);
QTRY_COMPARE(cstatspy.count(), 1);
arg = cstatspy.takeFirst();
QCOMPARE(arg.at(0).value<Akonadi::Collection::Id>(), monitorCol.id());
......@@ -204,11 +197,8 @@ void MonitorTest::testMonitor()
item.setPayload<QByteArray>("some new content");
ItemModifyJob *store = new ItemModifyJob(item, this);
AKVERIFYEXEC(store);
if (cstatspy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)), 1000));
}
QCOMPARE(cstatspy.count(), 1);
QTRY_COMPARE(cstatspy.count(), 1);
arg = cstatspy.takeFirst();
QCOMPARE(arg.at(0).value<Collection::Id>(), monitorCol.id());
......@@ -234,10 +224,7 @@ void MonitorTest::testMonitor()
// move an item
ItemMoveJob *move = new ItemMoveJob(item, res3);
AKVERIFYEXEC(move);
if (cstatspy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)), 1000));
}
QCOMPARE(cstatspy.count(), 2);
QTRY_COMPARE(cstatspy.count(), 2);
// NOTE: We don't make any assumptions about the order of the collectionStatisticsChanged
// signals, they seem to arrive in random order
QList<Collection::Id> notifiedCols;
......@@ -268,11 +255,8 @@ void MonitorTest::testMonitor()
// delete an item
ItemDeleteJob *del = new ItemDeleteJob(monitorRef, this);
AKVERIFYEXEC(del);
if (cstatspy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)), 1000));
}
QCOMPARE(cstatspy.count(), 1);
QTRY_COMPARE(cstatspy.count(), 1);
arg = cstatspy.takeFirst();
QCOMPARE(arg.at(0).value<Collection::Id>(), res3.id());
cmodspy.clear();
......@@ -303,16 +287,13 @@ void MonitorTest::testMonitor()
subscribeJob->unsubscribe(Collection::List() << subCollection);
AKVERIFYEXEC(subscribeJob);
// Wait for unsubscribed signal, it goes after changed, so we can check for both
if (cUnsubscribedSpy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionUnsubscribed(Akonadi::Collection)), 1000));
}
QCOMPARE(cmodspy.size(), 1);
QTRY_COMPARE(cmodspy.size(), 1);
arg = cmodspy.takeFirst();
col = arg.at(0).value<Collection>();
QCOMPARE(col.id(), subCollection.id());
QVERIFY(cSubscribedSpy.isEmpty());
QCOMPARE(cUnsubscribedSpy.size(), 1);
QTRY_COMPARE(cUnsubscribedSpy.size(), 1);
arg = cUnsubscribedSpy.takeFirst();
col = arg.at(0).value<Collection>();
QCOMPARE(col.id(), subCollection.id());
......@@ -321,16 +302,13 @@ void MonitorTest::testMonitor()
subscribeJob->subscribe(Collection::List() << subCollection);
AKVERIFYEXEC(subscribeJob);
// Wait for subscribed signal, it goes after changed, so we can check for both
if (cSubscribedSpy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionSubscribed(Akonadi::Collection,Akonadi::Collection)), 1000));
}
QCOMPARE(cmodspy.size(), 1);
QTRY_COMPARE(cmodspy.size(), 1);
arg = cmodspy.takeFirst();
col = arg.at(0).value<Collection>();
QCOMPARE(col.id(), subCollection.id());
QVERIFY(cUnsubscribedSpy.isEmpty());
QCOMPARE(cSubscribedSpy.size(), 1);
QTRY_COMPARE(cSubscribedSpy.size(), 1);
arg = cSubscribedSpy.takeFirst();
col = arg.at(0).value<Collection>();
QCOMPARE(col.id(), subCollection.id());
......@@ -353,11 +331,8 @@ void MonitorTest::testMonitor()
monitorCol.setName(QStringLiteral("changed name"));
CollectionModifyJob *mod = new CollectionModifyJob(monitorCol, this);
AKVERIFYEXEC(mod);
if (cmodspy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionChanged(Akonadi::Collection)), 1000));
}
QCOMPARE(cmodspy.count(), 1);
QTRY_COMPARE(cmodspy.count(), 1);
arg = cmodspy.takeFirst();
col = arg.at(0).value<Collection>();
QCOMPARE(col, monitorCol);
......@@ -380,11 +355,8 @@ void MonitorTest::testMonitor()
Collection dest = Collection(collectionIdFromPath(QStringLiteral("res1/foo")));
CollectionMoveJob *cmove = new CollectionMoveJob(monitorCol, dest, this);
AKVERIFYEXEC(cmove);
if (cmvspy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionMoved(Akonadi::Collection,Akonadi::Collection,Akonadi::Collection)), 1000));
}
QCOMPARE(cmvspy.count(), 1);
QTRY_COMPARE(cmvspy.count(), 1);
arg = cmvspy.takeFirst();
col = arg.at(0).value<Collection>();
QCOMPARE(col, monitorCol);
......@@ -411,11 +383,8 @@ void MonitorTest::testMonitor()
// delete a collection
CollectionDeleteJob *cdel = new CollectionDeleteJob(monitorCol, this);
AKVERIFYEXEC(cdel);
if (crmspy.isEmpty()) {
QVERIFY(AkonadiTest::akWaitForSignal(monitor, SIGNAL(collectionRemoved(Akonadi::Collection)), 1000));
}
QCOMPARE(crmspy.count(), 1);
QTRY_COMPARE(crmspy.count(), 1);
arg = crmspy.takeFirst();
col = arg.at(0).value<Collection>();
QCOMPARE(col.id(), monitorCol.id());
......@@ -435,15 +404,14 @@ void MonitorTest::testMonitor()
void MonitorTest::testVirtualCollectionsMonitoring()