diff --git a/cypress/e2e/sync.spec.js b/cypress/e2e/sync.spec.js index 715861bf65d..11f17f41d06 100644 --- a/cypress/e2e/sync.spec.js +++ b/cypress/e2e/sync.spec.js @@ -111,6 +111,7 @@ describe('Sync', () => { it('recovers from a lost and closed connection', () => { let reconnect = false + // block all requests until the session is closed and reopened cy.intercept('**/apps/text/session/*/*', (req) => { if (req.url.includes('close') || req.url.includes('create') || reconnect) { req.continue() @@ -125,6 +126,11 @@ describe('Sync', () => { cy.get('#editor-container .document-status', { timeout: 30000 }) .should('contain', 'Document could not be loaded.') + // Reconnect button works - it closes and reopens the session + cy.get('#editor-container .document-status a.button') + .contains('Reconnect') + .click() + cy.wait('@syncAfterRecovery', { timeout: 60000 }) cy.get('#editor-container .document-status', { timeout: 30000 }) diff --git a/src/services/SyncService.js b/src/services/SyncService.js index b2eda75c927..f758a9afa55 100644 --- a/src/services/SyncService.js +++ b/src/services/SyncService.js @@ -104,12 +104,14 @@ class SyncService { } async open({ fileId, initialSession }) { - + if (this.#connection && !this.#connection.isClosed) { + // We're already connected. + return + } const connect = initialSession ? Promise.resolve(new Connection({ data: initialSession }, {})) : this._api.open({ fileId, baseVersionEtag: this.baseVersionEtag }) .catch(error => this._emitError(error)) - this.#connection = await connect if (!this.#connection) { // Error was already emitted in connect