From 01c8b596eb645287d72e5c73564a4c53ce41a76a Mon Sep 17 00:00:00 2001 From: Martin Varmuza Date: Mon, 3 Feb 2025 15:22:28 +0100 Subject: [PATCH] test(suite): reload during discovery to test proper cleanup --- packages/connect/src/core/index.ts | 5 ++++- .../suite-web/e2e/tests/wallet/discovery.test.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/connect/src/core/index.ts b/packages/connect/src/core/index.ts index 1106f3db7a2..62a7946b8e0 100644 --- a/packages/connect/src/core/index.ts +++ b/packages/connect/src/core/index.ts @@ -715,8 +715,11 @@ const onCallDevice = async ( // TODO: This requires a massive refactoring https://github.com/trezor/trezor-suite/issues/5323 // @ts-expect-error TODO: messageResponse should be assigned from the response of "inner" function const response = messageResponse; - if (response) { + // todo: shouldReleaseSession should probably be removed (it was added recently). it looks like that we could + // receive 'disconnected during action' which does not mean that device got physically disconnected. + // see + // https://github.com/trezor/trezord-go/blob/db03d99230f5b609a354e3586f1dfc0ad6da16f7/usb/libusb.go#L545 const shouldReleaseSession = response.success || (!response.success && diff --git a/packages/suite-web/e2e/tests/wallet/discovery.test.ts b/packages/suite-web/e2e/tests/wallet/discovery.test.ts index f0ee800cf5c..dba2b715408 100644 --- a/packages/suite-web/e2e/tests/wallet/discovery.test.ts +++ b/packages/suite-web/e2e/tests/wallet/discovery.test.ts @@ -1,6 +1,8 @@ // @group_wallet // @retry=2 +import { getRandomInt } from '@trezor/utils'; + import { onNavBar } from '../../support/pageObjects/topBarObject'; // discovery should end within this time frame @@ -29,6 +31,18 @@ describe('Discovery', () => { cy.log('all available networks should return something from discovery'); cy.getTestElement('@dashboard/loading', { timeout: 1000 * 10 }); + + // wait randomly between 1000 and 3000 ms + cy.wait(getRandomInt(1, 40) * 100); + // trigger reload to simulate interruption. we want to make sure that communication with the device does not + // end up in some de-synced state. if this test becomes flaky, this reload might be the reason. + cy.reload(); + + // device appears as connected + cy.getTestElement('@deviceStatus-connected'); + // dashboard is still loading, discovery starts, no error appears + cy.getTestElement('@dashboard/loading'); + cy.getTestElement('@dashboard/loading', { timeout: DISCOVERY_LIMIT }).should('not.exist'); ['btc', ...coinsToActivate].forEach(symbol => { cy.getTestElement(`@wallet/coin-balance/value-${symbol}`);