Merge lp:~dobey/unity-scope-click/log-response-body into lp:unity-scope-click/devel

Proposed by dobey
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 251
Merged at revision: 252
Proposed branch: lp:~dobey/unity-scope-click/log-response-body
Merge into: lp:unity-scope-click/devel
Diff against target: 54 lines (+14/-4)
3 files modified
scope/click/webclient.cpp (+1/-1)
scope/tests/mock_network_access_manager.h (+6/-0)
scope/tests/test_webclient.cpp (+7/-3)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/log-response-body
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+218876@code.launchpad.net

Commit message

Add logging of the response body on network errors.

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
Alejandro J. Cura (alecu) wrote :

Please include the error number in the debug message, and the url that caused it since this is asynchronous.
Also, please add some tests.

review: Needs Fixing
Revision history for this message
dobey (dobey) wrote :

The error code is already being logged at a higher level. Should I move that into this lower level code?

The network tests are very flaky it seems. I had problems doing this at a higher level, as calling qDebug() would make several tests fail, with the signal not being emitted. I'm not sure if it's an issue with how we're using QObject here, or a deeper problem.

Revision history for this message
Alejandro J. Cura (alecu) wrote :

I still think that network_access_manager is the wrong layer to put this, so I've taken a look at the flaky tests when qDebug() was added to click::web::Response::errorHandler:
[ FAILED ] IndexTest.testSearchNetworkErrorIgnored
[ FAILED ] IndexTest.testGetDetailsNetworkErrorReported
[ FAILED ] ReviewsTest.testFetchReviewsNetworkErrorReported
[ FAILED ] WebClientTest.testResponseFailed

The quick fix is to add a new expect line in each failing test, like:
EXPECT_CALL(*reply, readAll()).Times(1).WillOnce(Return("{'fake': 'error'}"));

Furthermore, the first three tests should not be depending on this behaviour: they should not be mocking NetworkReply, but instead should be mocking WebClient. I think the quick fix is enough, though.

review: Needs Fixing
248. By dobey

Move the logging back up to the web::Response errorHandler.
Add a default return value for QByteArray in MockNetworkReply.

249. By dobey

Remove extraneous include.

250. By dobey

Use qWarning instead of qCritical for the error response body logging.

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)
251. By dobey

Combine the error string and the response body to a single qWarning.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Looks good now. Thanks for working on it!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scope/click/webclient.cpp'
2--- scope/click/webclient.cpp 2014-05-01 21:04:23 +0000
3+++ scope/click/webclient.cpp 2014-05-13 15:34:51 +0000
4@@ -174,7 +174,7 @@
5 void click::web::Response::errorHandler(QNetworkReply::NetworkError network_error)
6 {
7 auto message = reply->errorString() + QString(" (%1)").arg(network_error);
8- qDebug() << "emitting error: " << message;
9+ qWarning() << "Network error:" << message << "\n" << reply->readAll();
10 emit error(message);
11 }
12
13
14=== modified file 'scope/tests/mock_network_access_manager.h'
15--- scope/tests/mock_network_access_manager.h 2014-02-27 21:26:21 +0000
16+++ scope/tests/mock_network_access_manager.h 2014-05-13 15:34:51 +0000
17@@ -44,6 +44,12 @@
18 void sendError();
19
20 public:
21+ MockNetworkReply()
22+ {
23+ // Set a default value for QByteArray-returning mocked methods.
24+ ::testing::DefaultValue<QByteArray>::Set(QByteArray(""));
25+ }
26+
27 MOCK_METHOD0(abort, void());
28 MOCK_METHOD0(readAll, QByteArray());
29 MOCK_METHOD1(attribute, QVariant(QNetworkRequest::Attribute));
30
31=== modified file 'scope/tests/test_webclient.cpp'
32--- scope/tests/test_webclient.cpp 2014-05-01 21:04:23 +0000
33+++ scope/tests/test_webclient.cpp 2014-05-13 15:34:51 +0000
34@@ -309,13 +309,17 @@
35 EXPECT_CALL(nam, sendCustomRequest(_, _, _))
36 .Times(1)
37 .WillOnce(Return(replyPtr));
38- EXPECT_CALL(*reply, errorString()).Times(1).WillOnce(Return("fake error"));
39+ EXPECT_CALL(*reply, errorString())
40+ .Times(1)
41+ .WillOnce(Return("fake error"));
42+ EXPECT_CALL(*reply, readAll())
43+ .Times(1)
44+ .WillOnce(Return("{'error': 'Invalid request.'}"));
45
46 auto response = wc.call(FAKE_SERVER + FAKE_PATH);
47 QObject::connect(response.data(), &click::web::Response::error,
48- [this, &response](QString desc){
49+ [this](QString desc){
50 errorHandler(desc);
51- Q_UNUSED(response);
52 });
53
54 EXPECT_CALL(*this, errorHandler(_));

Subscribers

People subscribed via source and target branches

to all changes: