diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-10-19 11:42:42 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2022-10-19 12:38:28 +0300 |
commit | 064874c491e8977c4e632a93b1331a8b2e15c822 (patch) | |
tree | e2db56808efd0f37362dc4420ccacef7502d87d4 /test | |
parent | f362635937adfbe053185f46d3c2dd5a51e142b5 (diff) |
Implement a test for chunking ng fail due to a lock
Issue: owncloud/enterprise#5382
Diffstat (limited to 'test')
-rw-r--r-- | test/testchunkingng.cpp | 38 | ||||
-rw-r--r-- | test/testutils/syncenginetestutils.h | 26 |
2 files changed, 52 insertions, 12 deletions
diff --git a/test/testchunkingng.cpp b/test/testchunkingng.cpp index c84aeedfd..e01728caa 100644 --- a/test/testchunkingng.cpp +++ b/test/testchunkingng.cpp @@ -628,7 +628,45 @@ private slots: QCOMPARE(fakeFolder.currentRemoteState().find("A/a0")->contentSize, size + 1); } + // the final move fails but the succeeding sync recovers and finishes the upload + void testFinalMoveLocked() + { + FakeFolder fakeFolder { FileInfo::A12_B12_C12_S12() }; + const auto size = 15_mb; + setChunkSize(fakeFolder.syncEngine(), 1_mb); + + OperationCounter counter; + fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *device) -> QNetworkReply * { + counter.serverOverride(op, request, device); + if (request.attribute(QNetworkRequest::CustomVerbAttribute) == "MOVE") { + return new FakeErrorReply(op, request, this, 423, {}); + } + return nullptr; + }); + /* Insert a file. + * The file will be uploaded in chunks. + * in order to finish the upload the final file need to be moved to is destination. + * This move fails with a 423. + * Similar to the Folder class we will trigger a new sync but without the local discovery. + * The test ensures that we properly continue the download and only perform the final move. + */ + fakeFolder.localModifier().insert(QStringLiteral("A/a0"), size); + QVERIFY(fakeFolder.applyLocalModificationsAndSync()); + QVERIFY(fakeFolder.currentLocalState() != fakeFolder.currentRemoteState()); + QCOMPARE(counter.nMOVE, 1); + + counter.reset(); + fakeFolder.setServerOverride(counter.functor()); + + // do a partial discovery, don't actually list the local files + fakeFolder.syncEngine().setLocalDiscoveryOptions(OCC::LocalDiscoveryStyle::DatabaseAndFilesystem, {}); + QVERIFY(fakeFolder.applyLocalModificationsAndSync()); + QCOMPARE(counter.nDELETE, 0); + QCOMPARE(counter.nPUT, 0); + QCOMPARE(counter.nMOVE, 1); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + } }; QTEST_GUILESS_MAIN(TestChunkingNG) diff --git a/test/testutils/syncenginetestutils.h b/test/testutils/syncenginetestutils.h index 28dc036e0..2d5b13995 100644 --- a/test/testutils/syncenginetestutils.h +++ b/test/testutils/syncenginetestutils.h @@ -775,20 +775,22 @@ struct OperationCounter nDELETE = 0; } + QNetworkReply *serverOverride(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *) + { + if (op == QNetworkAccessManager::GetOperation) { + ++nGET; + } else if (op == QNetworkAccessManager::PutOperation) { + ++nPUT; + } else if (op == QNetworkAccessManager::DeleteOperation) { + ++nDELETE; + } else if (req.attribute(QNetworkRequest::CustomVerbAttribute) == QLatin1String("MOVE")) { + ++nMOVE; + } + return nullptr; + } auto functor() { - return [&](QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *) { - if (op == QNetworkAccessManager::GetOperation) { - ++nGET; - } else if (op == QNetworkAccessManager::PutOperation) { - ++nPUT; - } else if (op == QNetworkAccessManager::DeleteOperation) { - ++nDELETE; - } else if (req.attribute(QNetworkRequest::CustomVerbAttribute) == QLatin1String("MOVE")) { - ++nMOVE; - } - return nullptr; - }; + return [this](QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *device) { return serverOverride(op, req, device); }; } OperationCounter(FakeFolder &fakeFolder) |