diff --git a/test/testutils/syncenginetestutils.cpp b/test/testutils/syncenginetestutils.cpp index cec398e2bde..e77b1d1958a 100644 --- a/test/testutils/syncenginetestutils.cpp +++ b/test/testutils/syncenginetestutils.cpp @@ -12,6 +12,7 @@ #include "gui/accountmanager.h" #include "httplogger.h" #include "libsync/configfile.h" +#include "libsync/syncresult.h" #include @@ -132,6 +133,9 @@ bool DiskFileModifier::applyModifications() std::this_thread::sleep_for(50ms); QThread::currentThread()->eventDispatcher()->processEvents(QEventLoop::AllEvents); } while (!helper.finished); + if (!helper.succeeded) { + qWarning() << Q_FUNC_INFO << "failed"; + } return helper.succeeded; } @@ -1169,6 +1173,31 @@ FileInfo FakeFolder::dbState() const return result; } +bool FakeFolder::execUntilFinished() +{ + QSignalSpy spy(_syncEngine.get(), &OCC::SyncEngine::finished); + bool ok = spy.wait(3600000); + Q_ASSERT(ok && "Sync timed out"); + return spy[0][0].toBool(); +} + +bool FakeFolder::syncOnce() +{ + QObject connectScope; + QList> errors; + connect(_syncEngine.get(), &OCC::SyncEngine::syncError, &connectScope, + [&errors](const QString &message, OCC::ErrorCategory category) { errors << qMakePair(message, category); }); + OCC::SyncResult result; + connect( + _syncEngine.get(), &OCC::SyncEngine::itemCompleted, &connectScope, [&result](const OCC::SyncFileItemPtr &item) { result.processCompletedItem(item); }); + scheduleSync(); + const bool ok = execUntilFinished(); + if (!ok) { + qWarning() << Q_FUNC_INFO << "failed. Errors:" << errors << "Another sync needed:" << _syncEngine->isAnotherSyncNeeded() << result.errorStrings(); + } + return ok; +} + OCC::SyncFileItemPtr ItemCompletedSpy::findItem(const QString &path) const { for (const QList &args : *this) { diff --git a/test/testutils/syncenginetestutils.h b/test/testutils/syncenginetestutils.h index 9e8c41ff278..fbcd80a51fe 100644 --- a/test/testutils/syncenginetestutils.h +++ b/test/testutils/syncenginetestutils.h @@ -610,19 +610,9 @@ class FakeFolder : public QObject void execUntilItemCompleted(const QString &relativePath); - bool execUntilFinished() - { - QSignalSpy spy(_syncEngine.get(), &OCC::SyncEngine::finished); - bool ok = spy.wait(3600000); - Q_ASSERT(ok && "Sync timed out"); - return spy[0][0].toBool(); - } + bool execUntilFinished(); - bool syncOnce() - { - scheduleSync(); - return execUntilFinished(); - } + bool syncOnce(); Q_REQUIRED_RESULT bool applyLocalModificationsAndSync() {