graceful-shutdown.spec.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { ensureUserExists, login } from './helpers/login'
  2. import {
  3. isExcludedBySharding,
  4. STARTUP_TIMEOUT,
  5. startWith,
  6. } from './helpers/config'
  7. import { dockerCompose, getRedisKeys } from './helpers/hostAdminClient'
  8. import { createProject } from './helpers/project'
  9. import { prepareWaitForNextCompileSlot } from './helpers/compile'
  10. const USER = 'user@example.com'
  11. const PROJECT_NAME = 'Old Project'
  12. function bringServerProBackUp() {
  13. cy.log('bring server pro back up')
  14. cy.then({ timeout: STARTUP_TIMEOUT }, async () => {
  15. await dockerCompose('up', '--detach', '--wait', 'sharelatex')
  16. })
  17. }
  18. describe('GracefulShutdown', function () {
  19. if (isExcludedBySharding('PRO_CUSTOM_1')) return
  20. startWith({
  21. pro: true,
  22. withDataDir: true,
  23. resetData: true,
  24. })
  25. ensureUserExists({ email: USER })
  26. let projectId: string
  27. it('should display banner and flush changes out of redis', () => {
  28. bringServerProBackUp()
  29. login(USER)
  30. const { recompile, waitForCompile } = prepareWaitForNextCompileSlot()
  31. waitForCompile(() => {
  32. createProject(PROJECT_NAME).then(id => {
  33. projectId = id
  34. })
  35. })
  36. cy.log('add additional content')
  37. cy.findByText('\\maketitle').parent().click()
  38. cy.findByText('\\maketitle').parent().type(`\n\\section{{}New Section}`)
  39. recompile()
  40. cy.log(
  41. 'check flush from frontend to backend: should include new section in PDF'
  42. )
  43. cy.get('.pdf-viewer').should('contain.text', 'New Section')
  44. cy.log('should have unflushed content in redis before shutdown')
  45. cy.then(async () => {
  46. const keys = await getRedisKeys()
  47. expect(keys).to.contain(`DocsIn:${projectId}`)
  48. expect(keys).to.contain(`ProjectHistory:Ops:{${projectId}}`)
  49. })
  50. cy.log('trigger graceful shutdown')
  51. let pendingShutdown: Promise<any>
  52. cy.then(() => {
  53. pendingShutdown = dockerCompose('stop', '--timeout=60', 'sharelatex')
  54. })
  55. cy.log('wait for banner')
  56. cy.findByText(/performing maintenance/)
  57. cy.log('wait for page reload')
  58. cy.findByText(/is currently down for maintenance/)
  59. cy.log('wait for shutdown to complete')
  60. cy.then({ timeout: 60 * 1000 }, async () => {
  61. await pendingShutdown
  62. })
  63. cy.log('should not have any unflushed content in redis after shutdown')
  64. cy.then(async () => {
  65. const keys = await getRedisKeys()
  66. expect(keys).to.not.contain(`DocsIn:${projectId}`)
  67. expect(keys).to.not.contain(`ProjectHistory:Ops:{${projectId}}`)
  68. })
  69. bringServerProBackUp()
  70. cy.then(() => {
  71. cy.visit(`/project/${projectId}?trick-cypress-into-page-reload=true`)
  72. })
  73. cy.log('check loading doc from mongo')
  74. cy.findByText('New Section')
  75. cy.log('check PDF')
  76. cy.get('.pdf-viewer').should('contain.text', 'New Section')
  77. cy.log('check history')
  78. cy.findByText('History').click()
  79. cy.findByText(/\\section\{New Section}/)
  80. })
  81. })