Skip to content

Commit

Permalink
Fix unit test now that we really abort the sync
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Nov 24, 2023
1 parent 2b95e9f commit b87a569
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions test/testchunkingng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ private slots:
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

// Check what happens when we abort during the final MOVE and the
// the final MOVE is short enough for the abort-delay to help
// Check what happens when we abort during the final MOVE.
// The move succeeds on the server but as we abort it we won't realize in time.
// This means that the current sync fails, as it is aborted, but the MOVE was still performed on the server.
// Resulting in the local state being the same as the remote state.
void testLateAbortRecoverable()
{
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
Expand All @@ -344,18 +346,31 @@ private slots:
fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * {
if (request.attribute(QNetworkRequest::CustomVerbAttribute).toByteArray() == "MOVE") {
QTimer::singleShot(50ms, &parent, [&]() { fakeFolder.syncEngine().abort(); });
// while the response is delayed, the move is performed in the constructor, thus it happens immediately
return new DelayedReply<FakeChunkMoveReply>(responseDelay, fakeFolder.uploadState(), fakeFolder.remoteModifier(), op, request, &parent);
}
return nullptr;
});

// Test 1: NEW file aborted
fakeFolder.localModifier().insert(QStringLiteral("A/a0"), size);
// the sync will be aborted and thus fail
QVERIFY(!fakeFolder.applyLocalModificationsAndSync());
// the move was still performed
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

// update the meta data after the aborted sync
QVERIFY(fakeFolder.applyLocalModificationsAndSync());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

// Test 2: modified file upload aborted
fakeFolder.localModifier().appendByte(QStringLiteral("A/a0"));
// the sync will be aborted and thus fail
QVERIFY(!fakeFolder.applyLocalModificationsAndSync());
// the move was still performed
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

// update the meta data after the aborted sync
QVERIFY(fakeFolder.applyLocalModificationsAndSync());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
Expand Down

0 comments on commit b87a569

Please sign in to comment.