Merge lp:~osomon/webbrowser-app/shouldCancelRequests-handle-errors into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Ugo Riboni
Approved revision: 1227
Merged at revision: 1231
Proposed branch: lp:~osomon/webbrowser-app/shouldCancelRequests-handle-errors
Merge into: lp:webbrowser-app
Diff against target: 84 lines (+22/-13)
1 file modified
tests/unittests/favicon-fetcher/tst_FaviconFetcherTests.cpp (+22/-13)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/shouldCancelRequests-handle-errors
Reviewer Review Type Date Requested Status
Ugo Riboni (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+273735@code.launchpad.net

Commit message

Handle RemoteHostClosedError in shouldCancelRequests().

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ugo Riboni (uriboni) wrote :

Complicated issue, but from the way I understand it the solution seems to make sense.
Assuming that all errors happen, if they do happen, before 500ms sounds safe enough, as these things go.
Jenkins is also happy, therefore approving, as I can't think of cases when this will make things worse than they already are anyway.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/unittests/favicon-fetcher/tst_FaviconFetcherTests.cpp'
--- tests/unittests/favicon-fetcher/tst_FaviconFetcherTests.cpp 2015-09-21 19:41:22 +0000
+++ tests/unittests/favicon-fetcher/tst_FaviconFetcherTests.cpp 2015-10-07 17:51:27 +0000
@@ -52,7 +52,9 @@
52public:52public:
53 TestHTTPServer(QObject* parent = 0)53 TestHTTPServer(QObject* parent = 0)
54 : QTcpServer(parent)54 : QTcpServer(parent)
55 {}55 {
56 connect(this, SIGNAL(newConnection()), SLOT(onNewConnection()));
57 }
5658
57 QString baseURL() const59 QString baseURL() const
58 {60 {
@@ -61,17 +63,18 @@
6163
62Q_SIGNALS:64Q_SIGNALS:
63 void gotRequest(const QString& path) const;65 void gotRequest(const QString& path) const;
66 void gotError() const;
6467
65protected:68private Q_SLOTS:
66 void incomingConnection(qintptr socketDescriptor)69 void onNewConnection() {
67 {70 if (hasPendingConnections()) {
68 QTcpSocket* socket = new QTcpSocket(this);71 QTcpSocket* socket = nextPendingConnection();
69 connect(socket, SIGNAL(readyRead()), SLOT(readClient()));72 connect(socket, SIGNAL(readyRead()), SLOT(readClient()));
70 connect(socket, SIGNAL(disconnected()), SLOT(discardClient()));73 connect(socket, SIGNAL(disconnected()), SLOT(discardClient()));
71 socket->setSocketDescriptor(socketDescriptor);74 connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SIGNAL(gotError()));
75 }
72 }76 }
7377
74private Q_SLOTS:
75 void readClient()78 void readClient()
76 {79 {
77 QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());80 QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
@@ -141,6 +144,7 @@
141 QSignalSpy* fetcherSpy;144 QSignalSpy* fetcherSpy;
142 TestHTTPServer* server;145 TestHTTPServer* server;
143 QSignalSpy* serverSpy;146 QSignalSpy* serverSpy;
147 QSignalSpy* errorSpy;
144148
145private Q_SLOTS:149private Q_SLOTS:
146 void init()150 void init()
@@ -154,10 +158,12 @@
154 server = new TestHTTPServer;158 server = new TestHTTPServer;
155 server->listen();159 server->listen();
156 serverSpy = new QSignalSpy(server, SIGNAL(gotRequest(const QString&)));160 serverSpy = new QSignalSpy(server, SIGNAL(gotRequest(const QString&)));
161 errorSpy = new QSignalSpy(server, SIGNAL(gotError()));
157 }162 }
158163
159 void cleanup()164 void cleanup()
160 {165 {
166 delete errorSpy;
161 delete serverSpy;167 delete serverSpy;
162 delete server;168 delete server;
163 delete fetcherSpy;169 delete fetcherSpy;
@@ -278,14 +284,17 @@
278 void shouldCancelRequests()284 void shouldCancelRequests()
279 {285 {
280 // Issue several requests rapidly in succession, and verify that286 // Issue several requests rapidly in succession, and verify that
281 // all the previous ones are discarded287 // all the previous ones are discarded. Take into account possible
282 for (int i = 1; i < 10; ++i) {288 // errors (see https://launchpad.net/bugs/1498539).
289 int requests = 100;
290 int errors = 0;
291 for (int i = 1; i <= requests; ++i) {
283 QUrl url(server->baseURL() + "/favicon" + QString::number(i) + ".ico");292 QUrl url(server->baseURL() + "/favicon" + QString::number(i) + ".ico");
284 fetcher->setUrl(url);293 fetcher->setUrl(url);
285 QVERIFY(serverSpy->wait());294 QVERIFY(serverSpy->wait(500) || (errorSpy->count() == ++errors));
286 }295 }
287 QVERIFY(fetcherSpy->wait());296 QVERIFY(fetcherSpy->wait());
288 QCOMPARE(serverSpy->count(), 9);297 QCOMPARE(serverSpy->count() + errorSpy->count(), requests);
289 QCOMPARE(fetcherSpy->count(), 1);298 QCOMPARE(fetcherSpy->count(), 1);
290 }299 }
291};300};

Subscribers

People subscribed via source and target branches

to status/vote changes: