Skip to content

Commit

Permalink
Make unit test failure more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Aug 30, 2023
1 parent 5361bbb commit 3b5844e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
29 changes: 29 additions & 0 deletions test/testutils/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "gui/accountmanager.h"
#include "httplogger.h"
#include "libsync/configfile.h"
#include "libsync/syncresult.h"

#include <thread>

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<QPair<QString, OCC::ErrorCategory>> 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<QVariant> &args : *this) {
Expand Down
14 changes: 2 additions & 12 deletions test/testutils/syncenginetestutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 3b5844e

Please sign in to comment.