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
11 changes: 11 additions & 0 deletions cypress/e2e/SessionApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,16 @@ describe('The session Api', function() {
})
})

// Failed with a probability of ~ 50% initially
it('ignores steps stored after close cleaned up', function() {
cy.pushAndClose({ connection, steps: [messages.update], version })
cy.createTextSession(undefined, { filePath: '', shareToken })
.then(con => {
connection = con
})
.its('state.documentSource')
.should('eql', '## Hello world\n')
})

})
})
11 changes: 11 additions & 0 deletions cypress/support/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ Cypress.Commands.add('syncSteps', (connection, options = { version: 0 }) => {
return connection.sync(options)
.then(response => response.data)
})

// Used to test for race conditions between the last push and the close request
Cypress.Commands.add('pushAndClose', ({ connection, steps, version, awareness = '' }) => {
cy.log('Race between push and close')
.then(() => {
const push = connection.push({ steps, version, awareness })
.catch(e => e) // handle 403 gracefully
const close = connection.close()
return Promise.all([push, close])
})
})
6 changes: 3 additions & 3 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public function create($fileId = null, $filePath = null, $token = null, $guestNa
$readOnly = $this->documentService->isReadOnly($file, $token);

$this->sessionService->removeInactiveSessions($file->getId());
$activeSessions = $this->sessionService->getActiveSessions($file->getId());
$remainingSessions = $this->sessionService->getAllSessions($file->getId());
$freshSession = false;
if ($forceRecreate || count($activeSessions) === 0) {
if ($forceRecreate || count($remainingSessions) === 0) {
$freshSession = true;
try {
$this->documentService->resetDocument($file->getId(), $forceRecreate);
$freshSession = true;
} catch (DocumentHasUnsavedChangesException $e) {
}
}
Expand Down