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

Add additional Sentry E2E tests #20425

Merged
merged 10 commits into from
Aug 16, 2023
Merged

Add additional Sentry E2E tests #20425

merged 10 commits into from
Aug 16, 2023

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Aug 8, 2023

Explanation

Additional E2E tests have been added for our Sentry error handling.

Before this PR, the Sentry e2e tests before initialization only tested background errors, and the after initialization tests only tested UI errors. Now both types of errors are tested in both scenarios.

Tests have been added to test the state object sent along with each Sentry error as well. At the moment this object is empty in some circumstances, but this will change in later PRs.

To trigger background errors for testing, a new controller API method has been added that throws a test error. This mirrors a similar test function in the UI. A @deprecated tag was used to warn against using this accidentally in real code.

State snapshots have been added to make it easier to track changes to the Sentry state in future PRs. This will be very useful for the next few PRs, but might be less valuable long-term. We should consider removing it after the next few Sentry state changes to reduce maintenance burdens. State snapshots can be updated by setting the environment variable UPDATE_SNAPSHOTS to true when running tests, e.g.

UPDATE_SNAPSHOTS=true yarn test:e2e:single --browser chrome ./test/e2e/tests/errors.spec.js

Relates to #20449

Manual Testing Steps

N/A

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Merging #20425 (ad557db) into develop (9e302ea) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop   #20425      +/-   ##
===========================================
- Coverage    68.66%   68.64%   -0.02%     
===========================================
  Files          990      990              
  Lines        38274    38286      +12     
  Branches     10260    10262       +2     
===========================================
  Hits         26279    26279              
- Misses       11995    12007      +12     
Files Changed Coverage Δ
app/scripts/metamask-controller.js 64.27% <ø> (-0.29%) ⬇️
ui/index.js 0.00% <0.00%> (ø)
ui/store/actions.ts 43.36% <0.00%> (-0.05%) ⬇️

@Gudahtt Gudahtt marked this pull request as ready for review August 8, 2023 13:09
@Gudahtt Gudahtt requested a review from a team as a code owner August 8, 2023 13:09
@Gudahtt
Copy link
Member Author

Gudahtt commented Aug 8, 2023

Lots of distinct changes in this PR. I was tempted to split it up into separate PRs, but instead I left each change as a separate commit. Reviewing one commit at a time is advised.

@metamaskbot
Copy link
Collaborator

Builds ready [bcc40c2]
Page Load Metrics (1806 ± 56 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1252521652814
domContentLoaded16242126180411455
load16252126180611756
domInteractive16242126180411455
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 120 Bytes (0.00%)
  • ui: 210 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

* @deprecated This is only mean to facilitiate E2E testing. We should not
* use this for handling errors.
*/
throwError(message) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe make this a noop if we are not in dev or in test?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could! If this was called in a production build it would legitimately be an error though. Maybe it'd be better to throw, in case someone doesn't heed the deprecation notice.

Though... I should at least skip setting up the hook in the UI in test builds. We don't want people calling that in the web console. I'll update that to only set it up on test or dev builds.

Copy link
Member Author

Choose a reason for hiding this comment

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

Revised here: f4f1932
Let me know if that makes sense

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, that makes sense

// Wait for Sentry request
await driver.wait(async () => {
const isPending = await mockedEndpoint.isPending();
return isPending === false;
}, 10000);
}, 3000);
Copy link
Member Author

Choose a reason for hiding this comment

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

This was made 3000 to match the other test. If it takes longer than 3 seconds here for the request to arrive, then it implies the test where we're expecting it to never arrive isn't waiting long enough.

// Trigger error
driver.executeScript('window.stateHooks.throwTestError()');
Copy link
Member Author

Choose a reason for hiding this comment

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

These two lines were missing awaits

@metamaskbot
Copy link
Collaborator

Builds ready [f4f1932]
Page Load Metrics (1581 ± 40 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint106169133157
domContentLoaded1440178015808440
load1440178015818440
domInteractive1440178015808440
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 132 Bytes (0.00%)
  • ui: 222 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt Gudahtt requested a review from danjm August 9, 2023 16:17
@Gudahtt Gudahtt force-pushed the add-sentry-metric-state-tests branch from bec7666 to 8b1f49e Compare August 14, 2023 15:55
@@ -131,11 +383,10 @@ describe('Sentry errors', function () {
},
async ({ driver, mockedEndpoint }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
Copy link
Member Author

Choose a reason for hiding this comment

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

The login step was producing indeterminacy in the state snapshots because we didn't wait for the login process to finish. Rather than adding a waiting step, the login was removed (it wasn't necessary for the test).

@Gudahtt Gudahtt force-pushed the add-sentry-metric-state-tests branch 3 times, most recently from 16d947c to c4cd27d Compare August 14, 2023 18:08
@metamaskbot
Copy link
Collaborator

Builds ready [c4cd27d]
Page Load Metrics (1697 ± 48 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint119189140199
domContentLoaded1465190816969947
load1465190916979948
domInteractive1465190816969947
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 132 Bytes (0.00%)
  • ui: 222 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt Gudahtt force-pushed the add-sentry-metric-state-tests branch from c4cd27d to 78b025f Compare August 14, 2023 19:01
@metamaskbot
Copy link
Collaborator

Builds ready [78b025f]
Page Load Metrics (1521 ± 28 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint110174130147
domContentLoaded1410162315205828
load1410162315215928
domInteractive1410162315205828
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 132 Bytes (0.00%)
  • ui: 222 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt Gudahtt force-pushed the add-sentry-metric-state-tests branch 2 times, most recently from f2564db to d74cbdc Compare August 15, 2023 13:38
@Gudahtt Gudahtt added the release-blocker This bug is blocking the next release label Aug 15, 2023
@metamaskbot
Copy link
Collaborator

Builds ready [1d1557e]
Page Load Metrics (1563 ± 49 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint108161126136
domContentLoaded13841834156210149
load13841834156310149
domInteractive13841834156210149
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 132 Bytes (0.00%)
  • ui: 222 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

for (const field of dateFields) {
if (has(data, field)) {
set(data, field, typeof get(data, field));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

sleek lodash usage 😎

return;
}
throw error;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I was a bit confused by this function, wondering why we don't communicate anything about the deepStrictEqual failure and why we just update the snapshot instead of failing the test. But then I re-read the PR description and the default value of the update param and this makes sense. We do throw there error except in cases where UPDATE_SNAPSHOTS has been explicitly set, which would be done intentionally when the snapsshots are to be updated.

👍

@danjm
Copy link
Contributor

danjm commented Aug 15, 2023

Looks good to me. Nice improvements to the sentry error tests.

The tests have been reorganized into different describe blocks. Each
describe block is for either before or after initialization, and either
with or without opting into metrics.

This was done to simplify later test additions. The conditions for each
test are now in the describe block, letting us test additional things
in each of these conditions. The conditions were flattened to a single
level to avoid excessive indentation.
The Sentry e2e tests before initialization only tested background
errors, and the after initialization tests only tested UI errors. Now
both types of errors are tested in both scenarios.
E2E tests have been added to test the state object sent along with each
Sentry error.

At the moment this object is empty in some circumstances, but this will
change in later PRs.
The state hooks used for debugging and testing are now only included in
dev or test builds. The function name was updated and given a JSDoc
description to explain this more clearly as well.
State snapshot assertions have been added to the e2e error tests. These
snapshots will be very useful in reviewing a few PRs that will follow
this one.

We might decide to remove these snapshots after this set of Sentry
refactors, as they might be more work to maintain than they're worth.
But they will be useful at least in the short-term.

The login step has been removed from a few tests because it introduced
indeterminacy (the login process continued asynchronously after the
login, and sometimes was not finished when the error was triggered).
This fixes an intermittent failure on Firefox
The error screen only appears after a long timeout, and it doesn't
affect the next test steps at all.
@Gudahtt Gudahtt force-pushed the add-sentry-metric-state-tests branch from 1d1557e to ad557db Compare August 16, 2023 12:31
@metamaskbot
Copy link
Collaborator

Builds ready [ad557db]
Page Load Metrics (1453 ± 50 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint96160120178
domContentLoaded13021765145310550
load13021765145310550
domInteractive13021765145310550
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 132 Bytes (0.00%)
  • ui: 222 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@darkwing darkwing left a comment

Choose a reason for hiding this comment

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

Minor non-blocking nits re: 3000, but otherwise good!

);

// Wait for Sentry request
await driver.delay(3000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking nit but we may want to stick to known delay constants rather than an arbitrary number. Can be done in a follow up though.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah good call. This was copied from pre-existing tests in this file, and they should all be using a matching delay time, so I'll leave this for a follow-up.

await driver.wait(async () => {
const isPending = await mockedEndpoint.isPending();
return isPending === false;
}, 3000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same nit re: milliseconds

@Gudahtt Gudahtt merged commit a6ef7bb into develop Aug 16, 2023
@Gudahtt Gudahtt deleted the add-sentry-metric-state-tests branch August 16, 2023 14:22
@github-actions github-actions bot locked and limited conversation to collaborators Aug 16, 2023
@metamaskbot metamaskbot added the release-10.36.0 Issue or pull request that will be included in release 10.36.0 label Aug 16, 2023
@danjm danjm added release-10.34.5 Issue or pull request that will be included in release 10.34.5 and removed release-10.36.0 Issue or pull request that will be included in release 10.36.0 labels Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-10.34.5 Issue or pull request that will be included in release 10.34.5 release-blocker This bug is blocking the next release team-extension-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants