From cba0627a9c17caebd9126ddca721b96d262eb8dd Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 13 Jun 2018 14:20:21 +0200 Subject: [PATCH] Ensure GETFileJob notices finishing #6581 It could happen that readyRead was emitted for incoming data while the download was not yet finished. Then the network job could finish with no more data arriving - so readyRead wasn't emitted again. To fix this, the finished signal also gets connected to the readyRead slot. --- src/libsync/propagatedownload.cpp | 1 + test/syncenginetestutils.h | 9 +++++++++ test/testsyncengine.cpp | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index b90828b19c73c..5c0fb56454739 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -149,6 +149,7 @@ void GETFileJob::newReplyHook(QNetworkReply *reply) connect(reply, &QNetworkReply::metaDataChanged, this, &GETFileJob::slotMetaDataChanged); connect(reply, &QIODevice::readyRead, this, &GETFileJob::slotReadyRead); + connect(reply, &QNetworkReply::finished, this, &GETFileJob::slotReadyRead); connect(reply, &QNetworkReply::downloadProgress, this, &GETFileJob::downloadProgress); } diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 06c35d300e8a0..a84999cbfd74d 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -728,9 +728,18 @@ class FakeErrorReply : public QNetworkReply setAttribute(QNetworkRequest::HttpStatusCodeAttribute, _httpErrorCode); setError(InternalServerError, "Internal Server Fake Error"); emit metaDataChanged(); + emit readyRead(); + // finishing can come strictly after readyRead was called + QTimer::singleShot(5, this, &FakeErrorReply::slotSetFinished); + } + +public slots: + void slotSetFinished() { + setFinished(true); emit finished(); } +public: void abort() override { } qint64 readData(char *, qint64) override { return 0; } diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp index f546b56a96121..43117fea417a4 100644 --- a/test/testsyncengine.cpp +++ b/test/testsyncengine.cpp @@ -255,7 +255,8 @@ private slots: } else if(item->_file == "Y/Z/d3") { QVERIFY(item->_status != SyncFileItem::Success); } - QVERIFY(item->_file != "Y/Z/d9"); // we should have aborted the sync before d9 starts + // We do not know about the other files - maybe the sync was aborted, + // maybe they finished before the error caused the abort. } }