Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject when main request fails #1174

Merged
merged 19 commits into from
Jan 11, 2017
Merged

Conversation

Janpot
Copy link
Contributor

@Janpot Janpot commented Dec 17, 2016

Tests might need some reordering

@@ -203,6 +203,10 @@ class GatherRunner {
log.log('status', status);
return driver.endNetworkCollect();
}).then(networkRecords => {
if (driver.online && networkRecords[0].failed) {
log.error('statusEnd', networkRecords[0].localizedFailDescription);
return Promise.reject(new Error(networkRecords[0].localizedFailDescription));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something more friendly for the message?

`${options.url} could not be resolved`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The request could've failed for other reasons than 'not resolved'. Maybe my PR title is a bit too specific.

online: false,
endNetworkCollect() {
return Promise.resolve(
recordsFromLogs(require('./fixtures/unresolved-perflog.json'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well require this once, at the top of the file.

.then(_ => {
assert.ok(false);
}, error => {
assert.ok(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check doesn't do much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean? The result throws when run resolves and resolves when run throws. What do you suggest instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant that you're checking if you get here, the promise rejects. But there's another assert.equal that falls under this rejection too. I think it's fine too keep as you have. Doesn't hurt.

return Runner.run({}, {url, config, driverMock: unresolvedDriver})
.then(_ => {
assert.ok(true);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should have a reject case here with assert.ok(false);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Mocha handles rejected promises just fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with 151-153 and make sure your code isn't throwing.

@ebidel
Copy link
Contributor

ebidel commented Dec 30, 2016

Nice change. I've been bitten by a faulty url a couple of times when LH tests the offline page in Chrome :)

Is there a way to exit cleanly in this case without causing a runtime error? Similar to what LH does when you do not provide a URL. Although catching the error is better than we had before, this is fairly unfriendly:

screen shot 2016-12-30 at 10 53 15 am

@Janpot Janpot changed the title Reject when domain name can’t be resolved Reject when main request fails Dec 31, 2016
@paulirish
Copy link
Member

@ebidel use yarn run instead of npm run to make the bottom of that screenshot not terrible. :)

@ebidel
Copy link
Contributor

ebidel commented Jan 4, 2017

This works for me.

@ebidel
Copy link
Contributor

ebidel commented Jan 4, 2017

Leaving it open for anyone else to add comments.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good.

This error will also need to be handled in the extension here so we don't get a bunch of issues filed for testing non existent pages :)

@@ -126,6 +128,61 @@ describe('Runner', () => {
});
});

it('rejects when domain name can\'t be resolved', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if these could be narrowed in scope by adding them to gather-runner-test.js instead and cutting out Runner from the tests

@@ -241,8 +242,15 @@ function showProtocolTimeoutError() {
process.exit(_PROTOCOL_TIMEOUT_EXIT_CODE);
}

function showPageLoadError() {
console.error('Unable to load the page.');
process.exit(_PAGE_LOAD_ERROR_EXIT_CODE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting. Any reason to have a special error code (vs using _RUNTIME_ERROR_CODE)? No big deal if so, we added _PROTOCOL_TIMEOUT_EXIT_CODE specifically because we needed to detect that case for Travis retries

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, no reason. Just trying to match the style of the surrounding code. Will change to _RUNTIME_ERROR_CODE

@@ -241,8 +242,15 @@ function showProtocolTimeoutError() {
process.exit(_PROTOCOL_TIMEOUT_EXIT_CODE);
}

function showPageLoadError() {
console.error('Unable to load the page.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add something friendly here about rechecking the URL and that the page is actually working?

@@ -203,6 +203,12 @@ class GatherRunner {
log.log('status', status);
return driver.endNetworkCollect();
}).then(networkRecords => {
if (driver.online && networkRecords[0].failed) {
log.error('statusEnd', networkRecords[0].localizedFailDescription);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.error('GatherRunner', networkRecords[0].localizedFailDescription);

@Janpot
Copy link
Contributor Author

Janpot commented Jan 7, 2017

@brendankenny Can you take another look?
screen shot 2017-01-07 at 14 54 11

@ebidel
Copy link
Contributor

ebidel commented Jan 10, 2017

@Janpot can you look into the failing tests?

@Janpot
Copy link
Contributor Author

Janpot commented Jan 11, 2017

@ebidel Ok, so I can't reproduce this locally but here's what's happening on travis for some reason:

It fails on http://localhost:10200/dobetterweb/dbw_tester.html in smokehouse:

apparently networkRecords are not in order. On travis I get a first entry networkRecords[0] for 'http://localhost:10200/dobetterweb/dbw_partial_a.html' Instead of 'http://localhost:10200/dobetterweb/dbw_tester.html'. This entry fails because for some reason it is blocked by csp (_blockedReason: 'csp'). I'm not sure why this is happening but maybe it is something you want to look into as it seems an unexpected side effect of the dbw test?

In the meantime I will fix the logic by selecting the correct resource with the url. Will have to refactor a few things as there's a lot of mocking in the tests that breaks when I add my solution. Will continue on this when I have time again.

@Janpot
Copy link
Contributor Author

Janpot commented Jan 11, 2017

@ebidel Ok, seems to work now.

In case you want to check this, here's the strange line. This is a log of networkRecords[0] in afterPass. Notice it's not the main document and also the csp error. This doesn't happen on my machine.

@@ -172,6 +172,11 @@ document.addEventListener('DOMContentLoaded', _ => {
}
}

if (err.code === 'PAGE_LOAD_ERROR') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to add one last thing, but it would be great to fold this into the known error messages handling above. Error matching is on message string, not code, but since it appears we never actually expose the message directly, it would be easy to prefix mainRecord.localizedFailDescription with some string ('Unable to load the page: ' or whatever), then use that as the key in NON_BUG_ERROR_MESSAGES

@brendankenny
Copy link
Member

nice catch on network record ordering. Beyond the DBW smoke test CSP issue, it's nice to have the more robust search for the root network record in this PR

@Janpot
Copy link
Contributor Author

Janpot commented Jan 11, 2017

Another thing I noticed (but wasn't really an issue) was that chrome on Travis is out of date. Might want to clear the cache there once.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☁️ ➡️ ✂️ ➡️ 💻 🚫
LGTM!

@brendankenny brendankenny merged commit 3e1ddb6 into GoogleChrome:master Jan 11, 2017
@Janpot Janpot deleted the dns-error branch January 11, 2017 23:23
@Janpot
Copy link
Contributor Author

Janpot commented Jan 11, 2017

@brendankenny Your emoji's... Does it mean you're manually squashing and merging to master? If so, I'll make sure to squash and rebase in the future to save you the hassle (I usually use the GitHub squash+rebase)

@brendankenny
Copy link
Member

no, squashed via github UI

☁️ ➡️ ✂️ ➡️ 💻 🚫

Obviously this is a pictographic representation of displaying an error when the computer's connection to the test page (in the cloud) is severed :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants