diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2017-01-20 15:59:13 +0300 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2017-01-20 16:48:53 +0300 |
commit | a63d970e5ef39b6de3f55a75a4cabb8b4bbd18dc (patch) | |
tree | e88f72f8704e45972cc76d833748c58ca60cc986 /test/syncenginetestutils.h | |
parent | f6c77fad17060bf25f4e6591360340670ba2dd1c (diff) |
ChunkingNG: remove stale chunks when cleaning the uploadInfo table
Stale chunks might be there because a file was removed or would just not
be uploaded, for any reason.
We just start the DeleteJob but we don't care if it success or not.
Relates to https://github.com/owncloud/core/issues/26981
One of the test is testing the case where the file is modified on the server
during the upload. So this test the precondition failed error.
The FakeGetReply logic was modified because resizing a 150MB big QByteArray
by increment of 16k just did not scale when downloading a big file.
Diffstat (limited to 'test/syncenginetestutils.h')
-rw-r--r-- | test/syncenginetestutils.h | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index b2e52444b..f33096352 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -524,7 +524,8 @@ class FakeGetReply : public QNetworkReply Q_OBJECT public: const FileInfo *fileInfo; - QByteArray payload; + char payload; + int size; FakeGetReply(FileInfo &remoteRootFileInfo, QNetworkAccessManager::Operation op, const QNetworkRequest &request, QObject *parent) : QNetworkReply{parent} { @@ -540,8 +541,9 @@ public: } Q_INVOKABLE void respond() { - payload.fill(fileInfo->contentChar, fileInfo->size); - setHeader(QNetworkRequest::ContentLengthHeader, payload.size()); + payload = fileInfo->contentChar; + size = fileInfo->size; + setHeader(QNetworkRequest::ContentLengthHeader, size); setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200); setRawHeader("OC-ETag", fileInfo->etag.toLatin1()); setRawHeader("ETag", fileInfo->etag.toLatin1()); @@ -553,12 +555,12 @@ public: } void abort() override { } - qint64 bytesAvailable() const override { return payload.size() + QIODevice::bytesAvailable(); } + qint64 bytesAvailable() const override { return size + QIODevice::bytesAvailable(); } qint64 readData(char *data, qint64 maxlen) override { - qint64 len = std::min(qint64{payload.size()}, maxlen); - strncpy(data, payload.constData(), len); - payload.remove(0, len); + qint64 len = std::min(qint64{size}, maxlen); + std::fill_n(data, len, payload); + size -= len; return len; } }; @@ -607,7 +609,12 @@ public: Q_ASSERT(!fileName.isEmpty()); if ((fileInfo = remoteRootFileInfo.find(fileName))) { - QCOMPARE(request.rawHeader("If"), QByteArray("<" + request.rawHeader("Destination") + "> ([\"" + fileInfo->etag.toLatin1() + "\"])")); + QVERIFY(request.hasRawHeader("If")); // The client should put this header + if (request.rawHeader("If") != QByteArray("<" + request.rawHeader("Destination") + + "> ([\"" + fileInfo->etag.toLatin1() + "\"])")) { + QMetaObject::invokeMethod(this, "respondPreconditionFailed", Qt::QueuedConnection); + return; + } fileInfo->size = size; fileInfo->contentChar = payload; } else { @@ -632,6 +639,13 @@ public: emit finished(); } + Q_INVOKABLE void respondPreconditionFailed() { + setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 412); + setError(InternalServerError, "Precondition Failed"); + emit metaDataChanged(); + emit finished(); + } + void abort() override { } qint64 readData(char *, qint64) override { return 0; } }; |