Skip to content

Commit 6b509d1

Browse files
committed
chore(test): add test for receiving the root file ID during sync
Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
1 parent ab89674 commit 6b509d1

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

test/syncenginetestutils.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ void FakeQNAM::setServerVersion(const QString &version)
12231223
_serverVersion = version;
12241224
}
12251225

1226-
FakeFolder::FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo, const QString &remotePath)
1226+
FakeFolder::FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo, const QString &remotePath, const bool performInitialSync)
12271227
: _tempDirLocalPath(QFileInfo(_tempDir.path()).canonicalFilePath())
12281228
, _localModifier(_tempDirLocalPath)
12291229
{
@@ -1263,10 +1263,12 @@ FakeFolder::FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInf
12631263
// Ensure we have a valid VfsOff instance "running"
12641264
switchToVfs(_syncEngine->syncOptions()._vfs);
12651265

1266-
// A new folder will update the local file state database on first sync.
1267-
// To have a state matching what users will encounter, we have to a sync
1268-
// using an identical local/remote file tree first.
1269-
ENFORCE(syncOnce());
1266+
if (performInitialSync) {
1267+
// A new folder will update the local file state database on first sync.
1268+
// To have a state matching what users will encounter, we have to a sync
1269+
// using an identical local/remote file tree first.
1270+
ENFORCE(syncOnce());
1271+
}
12701272
}
12711273

12721274
void FakeFolder::switchToVfs(QSharedPointer<OCC::Vfs> vfs)

test/syncenginetestutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ class FakeFolder
604604
QString _serverVersion = QStringLiteral("10.0.0");
605605

606606
public:
607-
FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo = {}, const QString &remotePath = {});
607+
FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo = {}, const QString &remotePath = {}, const bool performInitialSync = true);
608608

609609
void switchToVfs(QSharedPointer<OCC::Vfs> vfs);
610610

test/testremotediscovery.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,26 @@ private slots:
221221
QCOMPARE(completeSpy.findItem("unlimited")->_folderQuota.bytesAvailable, -3);
222222
QCOMPARE(completeSpy.findItem("invalidValue")->_folderQuota.bytesAvailable, -1);
223223
}
224+
225+
void testRootFileIdReceived()
226+
{
227+
// disable FakeFolder's initial sync run to allow for spying on the `rootFileIdReceived` signal
228+
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12(), {}, {}, false };
229+
230+
QSignalSpy rootFileIdSpy(&fakeFolder.syncEngine(), &SyncEngine::rootFileIdReceived);
231+
QVERIFY(fakeFolder.syncOnce());
232+
233+
// root file id signal should only be emitted once
234+
QCOMPARE(rootFileIdSpy.size(), 1);
235+
const auto expectedRootFileId = fakeFolder.currentRemoteState().numericFileId();
236+
const auto receivedRootFileId = QByteArray::number(rootFileIdSpy.takeFirst().at(0).toLongLong(), 10);
237+
QCOMPARE(receivedRootFileId, expectedRootFileId);
238+
239+
// another sync should not emit the root file id signal again as it's already known
240+
rootFileIdSpy.clear();
241+
QVERIFY(fakeFolder.syncOnce());
242+
QCOMPARE(rootFileIdSpy.size(), 0);
243+
}
224244
};
225245

226246
QTEST_GUILESS_MAIN(TestRemoteDiscovery)

0 commit comments

Comments
 (0)