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

fix: flaky test 25912 #25913

Merged
merged 14 commits into from
Jul 23, 2024
Merged

fix: flaky test 25912 #25913

merged 14 commits into from
Jul 23, 2024

Conversation

hjetpoluru
Copy link
Contributor

@hjetpoluru hjetpoluru commented Jul 17, 2024

Description

This PR is to fix the flaky test associated with the 'User Operations from swap' test case. While I couldn't replicate the issue locally, the screenshots suggest a delay in transitioning from the swap action to clicking the close button.
Upon further investigation with @seaona, we determined that processing the swap transaction was taking time, as shown in the screenshot below. Consequently, a mock for the swap has been introduced.

Open in GitHub Codespaces

Related issues

Fixes: #25912

Manual testing steps

Run the test locally or in codespaces using below commands:
yarn
yarn build:test:flask
yarn test:e2e:single test/e2e/flask/user-operations.spec.ts --browser=chrome

Screenshots/Recordings

Before

Screenshot 2024-07-22 at 10 42 59 AM

After

Screenshot 2024-07-22 at 10 41 01 AM

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@hjetpoluru hjetpoluru requested a review from a team as a code owner July 17, 2024 20:47
@hjetpoluru hjetpoluru self-assigned this Jul 17, 2024
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Jul 17, 2024
@hjetpoluru hjetpoluru marked this pull request as draft July 17, 2024 22:53
@@ -102,7 +102,16 @@ async function createSwap(driver: Driver) {
swapFrom: 'TESTETH',
swapTo: 'USDC',
});

await driver.waitForSelector({ text: 'Swap', tag: 'button' });
Copy link
Contributor

Choose a reason for hiding this comment

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

this won''t have any effect as the clickElement function already waits for the element to be visible and clickable

{
text: 'View in activity',
tag: 'button',
},
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems that this is still no enough. From the flow we can know that:

  • the View in activity remains present until the tx is confirmed
  • once the tx is confirmed, the View in activity disappears and the Close button appears

In the failed tests screenshots we can see how we are still in the View activity phase, meaning that the transaction is not yet confirmed. I think we could investigate why the transaction takes so much to be confirmed. Maybe some mock is missing? 🤔

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree @seaona. Test has failed 4 times in this PR and as you suggested I will investigate why the transaction is taking longer than expected from the mocks perspective.

Copy link
Contributor

Choose a reason for hiding this comment

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

we can revert this change, as now we've seen that the root cause was that a mock was missing, causing a non-deterministic delay in the API response for the trades

@@ -429,6 +429,291 @@ const TRADES_API_MOCK_RESULT = [
},
];

const SWAP_TRANSACTION_TRADES_QUOTE_MOCK = [
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it can be good if we add a more explicit name, so it can be re-used in another test if needed. Something like:

Suggested change
const SWAP_TRANSACTION_TRADES_QUOTE_MOCK = [
const SWAP_ETH_USDC_TRADES_MOCK = [

@hjetpoluru hjetpoluru marked this pull request as ready for review July 22, 2024 18:42
@hjetpoluru hjetpoluru requested a review from seaona July 22, 2024 18:43
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request addresses the flaky test issue in the 'User Operations from swap' test case by introducing additional wait times and implementing checks to ensure the 'View in activity' button is absent.

  • test/data/mock-data.js: Added SWAP_TEST_ETH_USDC_TRADES_MOCK to support various swap scenarios.
  • test/e2e/flask/user-operations.spec.ts: Introduced mock data and server utility, added a function to mock swap transaction quotes, and updated test setup to use this mock function for consistent test conditions.

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@metamaskbot metamaskbot removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Jul 22, 2024
@hjetpoluru hjetpoluru requested a review from vthomas13 July 22, 2024 20:17
Copy link
Contributor

@seaona seaona left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work @hjetpoluru 🙌

Copy link
Contributor

@chloeYue chloeYue left a comment

Choose a reason for hiding this comment

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

LGTM ! Thanks for the fix !

@hjetpoluru
Copy link
Contributor Author

Thanks @seaona for helping me in analyzing and guiding the process.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR addresses the flaky test issue in the 'User Operations from swap' test case by introducing additional wait times and implementing checks to ensure the 'View in activity' button is absent.

  • test/e2e/flask/user-operations.spec.ts: Introduced mock data and server utility, added a function to mock swap transaction quotes, and updated test setup to use this mock function for consistent test conditions.
  • app/scripts/controllers/user-storage/user-storage-controller.ts: Updated isProfileSyncingEnabled property to allow a null value, requiring careful testing to ensure all code paths handle null correctly.
  • app/scripts/migrations/120.1.ts: Added migration to set isProfileSyncingEnabled to null in UserStorageController state, ensuring consistency in user data.
  • app/scripts/migrations/122.ts: Added migration to set redesignedConfirmationsEnabled to true in PreferencesController, enabling redesigned confirmations by default.
  • test/e2e/helpers.js: Introduced tempToggleSettingRedesignedConfirmations function to ensure redesigned confirmation settings are applied during tests.

47 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR addresses the flaky test issue in the 'User Operations from swap' test case by introducing mocks and additional wait times to stabilize the test.

  • .circleci/config.yml: Removed test-e2e-swap-playwright job to streamline CI pipeline.
  • app/scripts/background.js: Introduced mock implementations for Trezor and Ledger bridges in test environments.
  • app/scripts/lib/hardware-keyring-builder-factory.ts: Added FakeKeyringBridge type for improved testing.
  • test/e2e/api-specs/ConfirmationRejectionRule.ts: Simplified logic to always click 'Cancel' instead of 'Reject'.
  • test/stub/keyring-bridge.js: Added mock implementations for keyring bridges to improve test reliability.

8 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

codecov bot commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.68%. Comparing base (82382cd) to head (afefcf2).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #25913   +/-   ##
========================================
  Coverage    69.68%   69.68%           
========================================
  Files         1405     1405           
  Lines        49701    49701           
  Branches     13738    13738           
========================================
  Hits         34630    34630           
  Misses       15071    15071           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HowardBraham HowardBraham merged commit cebb0db into develop Jul 23, 2024
75 of 76 checks passed
@HowardBraham HowardBraham deleted the fix-flaky-test-25912 branch July 23, 2024 16:28
@github-actions github-actions bot locked and limited conversation to collaborators Jul 23, 2024
@metamaskbot metamaskbot added the release-12.3.0 Issue or pull request that will be included in release 12.3.0 label Jul 23, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [afefcf2]
Page Load Metrics (189 ± 192 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint743411345326
domContentLoaded10136382713
load471919189399192
domInteractive10136382713
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
flaky tests release-12.3.0 Issue or pull request that will be included in release 12.3.0 team-extension-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix "User Operations from swap" flaky tests
6 participants