diff options
author | Christian Kamm <mail@ckamm.de> | 2018-06-13 15:20:21 +0300 |
---|---|---|
committer | ckamm <mail@ckamm.de> | 2018-06-13 17:44:24 +0300 |
commit | ad2446b0360a22d412f30131bd9d6f2f20ac5134 (patch) | |
tree | 40d3c950fec4ebddf8704d4a9f5d608639fd18ab | |
parent | 9c66dbb2b77a581d56a4ef1000c8e55410e56cfb (diff) |
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.
-rw-r--r-- | src/libsync/propagatedownload.cpp | 1 | ||||
-rw-r--r-- | test/syncenginetestutils.h | 7 | ||||
-rw-r--r-- | test/testdownload.cpp | 3 | ||||
-rw-r--r-- | test/testsyncengine.cpp | 3 |
4 files changed, 13 insertions, 1 deletions
diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index ae9ddf7a8..55dbe8caa 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -147,6 +147,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 3957479d6..e0982bd15 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -729,10 +729,17 @@ public: 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 *buf, qint64 max) override { max = qMin<qint64>(max, _body.size()); diff --git a/test/testdownload.cpp b/test/testdownload.cpp index 4d9098e41..3301e0e6d 100644 --- a/test/testdownload.cpp +++ b/test/testdownload.cpp @@ -112,7 +112,10 @@ private slots: return nullptr; }); + bool timedOut = false; + QTimer::singleShot(10000, &fakeFolder.syncEngine(), [&]() { timedOut = true; fakeFolder.syncEngine().abort(); }); QVERIFY(!fakeFolder.syncOnce()); // Fail because A/broken + QVERIFY(!timedOut); QCOMPARE(getItem(completeSpy, "A/broken")->_status, SyncFileItem::NormalError); QVERIFY(getItem(completeSpy, "A/broken")->_errorString.contains(serverMessage)); } diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp index 08a28e681..5628befdc 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. } } |