Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cypress/e2e/sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 })
Expand Down
5 changes: 4 additions & 1 deletion src/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class SyncService {
}

async open({ fileId, initialSession }) {
if (this.#connection && !this.#connection.isClosed) {
// We're already connected.
return
}
const onChange = ({ sessions }) => {
this.sessions = sessions
}
Expand All @@ -116,7 +120,6 @@ class SyncService {
? 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) {
this.off('change', onChange)
Expand Down