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
1=== modified file 'tests/unittests/favicon-fetcher/tst_FaviconFetcherTests.cpp'
2--- tests/unittests/favicon-fetcher/tst_FaviconFetcherTests.cpp 2015-09-21 19:41:22 +0000
3+++ tests/unittests/favicon-fetcher/tst_FaviconFetcherTests.cpp 2015-10-07 17:51:27 +0000
4@@ -52,7 +52,9 @@
5 public:
6 TestHTTPServer(QObject* parent = 0)
7 : QTcpServer(parent)
8- {}
9+ {
10+ connect(this, SIGNAL(newConnection()), SLOT(onNewConnection()));
11+ }
12
13 QString baseURL() const
14 {
15@@ -61,17 +63,18 @@
16
17 Q_SIGNALS:
18 void gotRequest(const QString& path) const;
19+ void gotError() const;
20
21-protected:
22- void incomingConnection(qintptr socketDescriptor)
23- {
24- QTcpSocket* socket = new QTcpSocket(this);
25- connect(socket, SIGNAL(readyRead()), SLOT(readClient()));
26- connect(socket, SIGNAL(disconnected()), SLOT(discardClient()));
27- socket->setSocketDescriptor(socketDescriptor);
28+private Q_SLOTS:
29+ void onNewConnection() {
30+ if (hasPendingConnections()) {
31+ QTcpSocket* socket = nextPendingConnection();
32+ connect(socket, SIGNAL(readyRead()), SLOT(readClient()));
33+ connect(socket, SIGNAL(disconnected()), SLOT(discardClient()));
34+ connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SIGNAL(gotError()));
35+ }
36 }
37
38-private Q_SLOTS:
39 void readClient()
40 {
41 QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
42@@ -141,6 +144,7 @@
43 QSignalSpy* fetcherSpy;
44 TestHTTPServer* server;
45 QSignalSpy* serverSpy;
46+ QSignalSpy* errorSpy;
47
48 private Q_SLOTS:
49 void init()
50@@ -154,10 +158,12 @@
51 server = new TestHTTPServer;
52 server->listen();
53 serverSpy = new QSignalSpy(server, SIGNAL(gotRequest(const QString&)));
54+ errorSpy = new QSignalSpy(server, SIGNAL(gotError()));
55 }
56
57 void cleanup()
58 {
59+ delete errorSpy;
60 delete serverSpy;
61 delete server;
62 delete fetcherSpy;
63@@ -278,14 +284,17 @@
64 void shouldCancelRequests()
65 {
66 // Issue several requests rapidly in succession, and verify that
67- // all the previous ones are discarded
68- for (int i = 1; i < 10; ++i) {
69+ // all the previous ones are discarded. Take into account possible
70+ // errors (see https://launchpad.net/bugs/1498539).
71+ int requests = 100;
72+ int errors = 0;
73+ for (int i = 1; i <= requests; ++i) {
74 QUrl url(server->baseURL() + "/favicon" + QString::number(i) + ".ico");
75 fetcher->setUrl(url);
76- QVERIFY(serverSpy->wait());
77+ QVERIFY(serverSpy->wait(500) || (errorSpy->count() == ++errors));
78 }
79 QVERIFY(fetcherSpy->wait());
80- QCOMPARE(serverSpy->count(), 9);
81+ QCOMPARE(serverSpy->count() + errorSpy->count(), requests);
82 QCOMPARE(fetcherSpy->count(), 1);
83 }
84 };

Subscribers

People subscribed via source and target branches

to status/vote changes: