upgrading.spec.ts 7.2 KB

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