cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.69k stars 3.16k forks source link

[cy.session] cy.then() timed out after waiting 30000ms #19906

Closed iskathi closed 1 year ago

iskathi commented 2 years ago

Current behavior

cy.session fails in very long tests (over 15 minutes in my case)

image image

CypressError: `cy.then()` timed out after waiting `30000ms`.

Your callback function returned a promise that never resolved.

The callback function was:

async () => {
        if (!existingSession.hydrated) {
          const serverStoredSession = await sessions.getSession(existingSession.id).catch(lodash__WEBPACK_IMPORTED_MODULE_0___default.a.noop); // we have a saved session on the server AND setup matches

          if (serverStoredSession && serverStoredSession.setup === existingSession.setup.toString()) {
            lodash__WEBPACK_IMPORTED_MODULE_0___default.a.extend(existingSession, serverStoredSession);

            existingSession.hydrated = true;
          } else {
            onValidationError = throwValidationError;
            return runSetup(existingSession);
          }
        }

        Cypress.log({
          name: 'Restore Saved Session',
          event: true,
          state: 'passed',
          type: 'system',
          message: ``,
          groupStart: true
        });
        await navigateAboutBlank();

        _log.set({
          renderProps: () => {
            return {
              indicator: 'pending',
              message: `(saved) ${_log.get().message}`
            };
          }
        });

        dataLog.set({
          consoleProps: () => getConsoleProps(existingSession)
        });
        await sessions.setSessionData(existingSession);
      }
    at https://localhost:44301/__cypress/runner/cypress_runner.js:156066:83
From previous event:
    at Context.thenFn (https://localhost:44301/__cypress/runner/cypress_runner.js:156065:13)
    at Context.then (https://localhost:44301/__cypress/runner/cypress_runner.js:156509:21)
    at Context.<anonymous> (https://localhost:44301/__cypress/runner/cypress_runner.js:172859:19)
    at https://localhost:44301/__cypress/runner/cypress_runner.js:171717:15
From previous event:
    at CommandQueue.runCommand (https://localhost:44301/__cypress/runner/cypress_runner.js:171696:8)
    at next (https://localhost:44301/__cypress/runner/cypress_runner.js:171839:19)
From previous event:
    at next (https://localhost:44301/__cypress/runner/cypress_runner.js:171839:39)
    at https://localhost:44301/__cypress/runner/cypress_runner.js:171868:16

Desired behavior

Would be best if it did not fail

Test code to reproduce

I've managed to reproduce it with this tests after 2000 seconds

describe('sessions', () => {
    it('long', () => {
        cy.wrap(Cypress._.range(1, 200)).each((i: number) => {
            cy.session(`${i % 10}`, () => {
                cy.visit('https://www.tradingview.com/features/');
            });
            cy.visit('https://www.tradingview.com/news/');
            cy.wrap(Cypress._.range(1, 20)).each(() => {
                cy.get('[data-id="react-root"]').should('exist').should('be.visible');
            });
        });
    });
});

cypress.json

"redirectionLimit": 1000,

Cypress Version

9.3.1

Other

No response

tbiethman commented 2 years ago

@iskathi Thank you for the reproduction. I can confirm it produces posted error after running for some time.

BlueWinds commented 1 year ago

This doesn't seem to be related to cy.session, but rather the sheer number of assertions the test runs. The Cypress command log slows down heavily in large tests.

This is a real issue, and we're discussing how to fix it at the moment, but going to close as duplicate in favor of https://github.com/cypress-io/cypress/issues/4164, which contains links to other issues demonstrating the same slowdown without involving cy.origin.