Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.4] ensure that bulk upload network job errors are handled #4267

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libsync/bulkpropagatorjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,18 @@ void BulkPropagatorJob::slotPutFinished()

slotJobDestroyed(job); // remove it from the _jobs list

const auto jobError = job->reply()->error();

const auto replyData = job->reply()->readAll();
const auto replyJson = QJsonDocument::fromJson(replyData);
const auto fullReplyObject = replyJson.object();

for (const auto &singleFile : _filesToUpload) {
if (!fullReplyObject.contains(singleFile._remotePath)) {
if (jobError != QNetworkReply::NoError) {
singleFile._item->_status = SyncFileItem::NormalError;
abortWithError(singleFile._item, SyncFileItem::NormalError, tr("Network Error: %1").arg(jobError));
}
continue;
}
const auto singleReplyObject = fullReplyObject[singleFile._remotePath].toObject();
Expand Down
51 changes: 51 additions & 0 deletions test/testsyncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,57 @@ private slots:
QCOMPARE(nPUT, 6);
QCOMPARE(nPOST, 0);
}

/**
* Checks whether subsequent large uploads are skipped after a 507 error
*/
void testNetworkErrorsWithBulkUpload()
{
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{ {"bulkupload", "1.0"} } } });

// Disable parallel uploads
SyncOptions syncOptions;
syncOptions._parallelNetworkJobs = 0;
fakeFolder.syncEngine().setSyncOptions(syncOptions);

int nPUT = 0;
int nPOST = 0;
fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * {
auto contentType = request.header(QNetworkRequest::ContentTypeHeader).toString();
if (op == QNetworkAccessManager::PostOperation) {
++nPOST;
if (contentType.startsWith(QStringLiteral("multipart/related; boundary="))) {
return new FakeErrorReply(op, request, this, 400);
}
return nullptr;
} else if (op == QNetworkAccessManager::PutOperation) {
++nPUT;
}
return nullptr;
});

fakeFolder.localModifier().insert("A/big1", 1);
fakeFolder.localModifier().insert("A/big2", 1);
fakeFolder.localModifier().insert("A/big3", 1);
fakeFolder.localModifier().insert("A/big4", 1);
fakeFolder.localModifier().insert("A/big5", 1);
fakeFolder.localModifier().insert("A/big6", 1);
fakeFolder.localModifier().insert("A/big7", 1);
fakeFolder.localModifier().insert("A/big8", 1);
fakeFolder.localModifier().insert("B/big8", 1);

QVERIFY(!fakeFolder.syncOnce());
QCOMPARE(nPUT, 0);
QCOMPARE(nPOST, 1);
nPUT = 0;
nPOST = 0;

QVERIFY(fakeFolder.syncOnce());
QCOMPARE(nPUT, 9);
QCOMPARE(nPOST, 0);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
};

QTEST_GUILESS_MAIN(TestSyncEngine)
Expand Down