upgrading.spec.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import { ensureUserExists, login } from './helpers/login'
  2. import { isExcludedBySharding, startWith } from './helpers/config'
  3. import { dockerCompose, runScript } from './helpers/hostAdminClient'
  4. import { createProject, openProjectByName } from './helpers/project'
  5. import { throttledRecompile } from './helpers/compile'
  6. import { v4 as uuid } from 'uuid'
  7. const USER = 'user@example.com'
  8. const PROJECT_NAME = 'Old Project'
  9. describe('Upgrading', function () {
  10. if (isExcludedBySharding('PRO_CUSTOM_3')) return
  11. function testUpgrade(
  12. steps: {
  13. version: string
  14. vars?: Object
  15. newProjectButtonMatcher?: RegExp
  16. hook?: () => void
  17. }[]
  18. ) {
  19. const startOptions = steps.shift()!
  20. before(async () => {
  21. cy.log('Create old instance')
  22. })
  23. startWith({
  24. pro: true,
  25. version: startOptions.version,
  26. withDataDir: true,
  27. resetData: true,
  28. vars: startOptions.vars,
  29. })
  30. before(function () {
  31. cy.log('Create initial user after deleting it')
  32. })
  33. ensureUserExists({ email: USER })
  34. before(() => {
  35. cy.log('Populate old instance')
  36. login(USER)
  37. createProject(PROJECT_NAME, {
  38. newProjectButtonMatcher: startOptions.newProjectButtonMatcher,
  39. })
  40. const recompile = throttledRecompile()
  41. cy.log('Wait for successful compile')
  42. cy.get('.pdf-viewer').should('contain.text', PROJECT_NAME)
  43. cy.log('Increment the doc version three times')
  44. for (let i = 0; i < 3; i++) {
  45. cy.log('Add content')
  46. cy.findByText('\\maketitle').parent().click()
  47. cy.findByText('\\maketitle')
  48. .parent()
  49. .type(`\n\\section{{}Old Section ${i}}`)
  50. cy.log('Trigger full flush')
  51. recompile()
  52. cy.get('header').findByText('Menu').click()
  53. cy.findByText('Source').click()
  54. cy.get('.left-menu-modal-backdrop').click({ force: true })
  55. }
  56. cy.log('Check compile and history')
  57. for (let i = 0; i < 3; i++) {
  58. cy.get('.pdf-viewer').should('contain.text', `Old Section ${i}`)
  59. }
  60. cy.findByText('History').click()
  61. for (let i = 0; i < 3; i++) {
  62. cy.findByText(new RegExp(`\\\\section\{Old Section ${i}}`))
  63. }
  64. })
  65. for (const step of steps) {
  66. before(() => {
  67. cy.log(`Upgrade to version ${step.version}`)
  68. // Navigate way from editor to avoid redirect to /login when the next instance comes up (which slows down tests)
  69. cy.visit('/project', {})
  70. })
  71. before(async function () {
  72. cy.log('Graceful shutdown: flush all the things')
  73. this.timeout(20 * 1000)
  74. // Ideally we could use the container shutdown procedure, but it's too slow and unreliable for tests.
  75. // TODO(das7pad): adopt the below after speeding up the graceful shutdown procedure on all supported releases
  76. // await dockerCompose('stop', 'sharelatex')
  77. // For now, we are stuck with manually flushing things
  78. await runScript({
  79. cwd: 'services/document-updater',
  80. script: 'scripts/flush_all.js',
  81. })
  82. await runScript({
  83. cwd: 'services/project-history',
  84. script: 'scripts/flush_all.js',
  85. })
  86. })
  87. startWith({
  88. pro: true,
  89. version: step.version,
  90. vars: step.vars,
  91. withDataDir: true,
  92. })
  93. step.hook?.()
  94. }
  95. beforeEach(() => {
  96. login(USER)
  97. })
  98. it('should list the old project', () => {
  99. cy.visit('/project')
  100. cy.findByText(PROJECT_NAME)
  101. })
  102. it('should open the old project', () => {
  103. openProjectByName(PROJECT_NAME)
  104. cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
  105. cy.findByRole('navigation').within(() => {
  106. cy.findByText(PROJECT_NAME)
  107. })
  108. const recompile = throttledRecompile()
  109. cy.log('wait for successful compile')
  110. cy.get('.pdf-viewer').should('contain.text', PROJECT_NAME)
  111. cy.get('.pdf-viewer').should('contain.text', 'Old Section 2')
  112. cy.log('Add more content')
  113. const newSection = `New Section ${uuid()}`
  114. cy.findByText('\\maketitle').parent().click()
  115. cy.findByText('\\maketitle').parent().type(`\n\\section{{}${newSection}}`)
  116. cy.log('Check compile and history')
  117. recompile()
  118. cy.get('.pdf-viewer').should('contain.text', newSection)
  119. cy.findByText('History').click()
  120. cy.findByText(/\\section\{Old Section 2}/)
  121. cy.findByText(new RegExp(`\\\\section\\{${newSection}}`))
  122. })
  123. }
  124. const optionsFourDotTwo = {
  125. version: '4.2',
  126. vars: {
  127. // Add core vars with old branding
  128. SHARELATEX_SITE_URL: 'http://sharelatex',
  129. SHARELATEX_MONGO_URL: 'mongodb://mongo/sharelatex',
  130. SHARELATEX_REDIS_HOST: 'redis',
  131. },
  132. newProjectButtonMatcher: /create first project/i,
  133. }
  134. describe('from 4.2 to latest', () => {
  135. testUpgrade([optionsFourDotTwo, { version: 'latest' }])
  136. })
  137. describe('from 5.0 to latest', () => {
  138. testUpgrade([{ version: '5.0' }, { version: 'latest' }])
  139. })
  140. describe('doc version recovery', () => {
  141. testUpgrade([
  142. optionsFourDotTwo,
  143. {
  144. version: '5.0.1-RC1',
  145. hook() {
  146. before(function () {
  147. login(USER)
  148. cy.visit('/')
  149. cy.findByText(PROJECT_NAME).click()
  150. const recompile = throttledRecompile()
  151. cy.log('Make a change')
  152. cy.findByText('\\maketitle').parent().click()
  153. cy.findByText('\\maketitle')
  154. .parent()
  155. .type('\n\\section{{}FiveOOne Section}')
  156. cy.log('Trigger flush')
  157. recompile()
  158. cy.get('.pdf-viewer').should('contain.text', 'FiveOOne Section')
  159. cy.log('Check for broken history, i.e. not synced with latest edit')
  160. cy.findByText('History').click()
  161. cy.findByText(/\\section\{Old Section 2}/) // wait for lazy loading
  162. cy.findByText(/\\section\{FiveOOne Section}/).should('not.exist')
  163. })
  164. },
  165. },
  166. {
  167. version: 'latest',
  168. hook() {
  169. before(async function () {
  170. this.timeout(20_000)
  171. const needle = 'Finished resyncing history for all projects.'
  172. for (let i = 0; i < 30; i++) {
  173. const { stdout } = await dockerCompose('logs', 'sharelatex')
  174. if (stdout.includes(needle)) {
  175. return
  176. }
  177. await new Promise(resolve => setTimeout(resolve, 500))
  178. }
  179. const { stdout } = await dockerCompose('logs', 'sharelatex')
  180. expect(stdout).to.contain(
  181. needle,
  182. 'Doc version recovery did not finish yet.'
  183. )
  184. })
  185. before(function () {
  186. login(USER)
  187. cy.visit('/')
  188. cy.findByText(PROJECT_NAME).click()
  189. cy.log(
  190. 'The edit that was made while the history was broken should be there now.'
  191. )
  192. cy.findByText('History').click()
  193. cy.findByText(/\\section\{FiveOOne Section}/)
  194. // TODO(das7pad): restore after https://github.com/overleaf/internal/issues/19588 is fixed.
  195. // cy.log('Check indicator of force resync')
  196. // cy.findByText('Overleaf History System')
  197. })
  198. },
  199. },
  200. ])
  201. })
  202. })