From 024c86b22dd7c63850fd5697de6931f31f854d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 13 Jul 2023 00:10:42 +0200 Subject: [PATCH] tests(cypress): Refactor reconnect test to be more reliable and add second test for actual reconnect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- cypress/e2e/sync.spec.js | 53 +++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/cypress/e2e/sync.spec.js b/cypress/e2e/sync.spec.js index be2e3d1370d..a056372fa83 100644 --- a/cypress/e2e/sync.spec.js +++ b/cypress/e2e/sync.spec.js @@ -64,23 +64,22 @@ describe('Sync', () => { .should('include', 'saves the doc state') }) - it('recovers from a lost connection', () => { - let count = 0 - cy.intercept({ method: 'PUT', url: '**/apps/text/session/create' }) - .as('createSession') - cy.intercept({ method: 'POST', url: '**/apps/text/session/*' }, (req) => { - if (count < 4) { + it('recovers from a short lost connection', () => { + let reconnect = false + cy.intercept('**/apps/text/session/*', (req) => { + if (reconnect) { + req.continue() + req.alias = 'alive' + } else { req.destroy() req.alias = 'dead' - } else { - req.alias = 'alive' } }).as('sessionRequests') cy.wait('@dead', { timeout: 30000 }) cy.get('#editor-container .document-status', { timeout: 30000 }) .should('contain', 'File could not be loaded') .then(() => { - count = 4 + reconnect = true }) cy.wait('@alive', { timeout: 30000 }) cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }) @@ -89,10 +88,40 @@ describe('Sync', () => { cy.get('#editor-container .document-status', { timeout: 30000 }) .should('not.contain', 'File could not be loaded') // FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session - cy.wait('@createSession') - cy.wait('@syncAfterRecovery') + cy.wait('@syncAfterRecovery', { timeout: 10000 }) + cy.getContent().type('* more content added after the lost connection{enter}') + cy.wait('@syncAfterRecovery', { timeout: 10000 }) + cy.closeFile() + cy.testName() + .then(name => cy.downloadFile(`/${name}.md`)) + .its('data') + .should('include', 'after the lost connection') + }) + + it('recovers from a lost and closed connection', () => { + let reconnect = false + cy.intercept('**/apps/text/session/*', (req) => { + if (req.url.includes('close') || req.url.includes('create') || reconnect) { + req.continue() + req.alias = 'syncAfterRecovery' + reconnect = true + } else { + req.destroy() + } + }).as('sessionRequests') + + cy.wait('@sessionRequests', { timeout: 30000 }) + cy.get('#editor-container .document-status', { timeout: 30000 }) + .should('contain', 'File could not be loaded') + + cy.wait('@syncAfterRecovery', { timeout: 60000 }) + + cy.get('#editor-container .document-status', { timeout: 30000 }) + .should('not.contain', 'File could not be loaded') + // FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session + cy.wait('@syncAfterRecovery', { timeout: 10000 }) cy.getContent().type('* more content added after the lost connection{enter}') - cy.wait('@syncAfterRecovery') + cy.wait('@syncAfterRecovery', { timeout: 10000 }) cy.closeFile() cy.testName() .then(name => cy.downloadFile(`/${name}.md`))