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 { throttledRecompile } 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. cy.visit('/project')
  31. createProject(PROJECT_NAME).then(id => {
  32. projectId = id
  33. })
  34. const recompile = throttledRecompile()
  35. cy.log('add additional content')
  36. cy.findByText('\\maketitle').parent().click()
  37. cy.findByText('\\maketitle').parent().type(`\n\\section{{}New Section}`)
  38. recompile()
  39. cy.log(
  40. 'check flush from frontend to backend: should include new section in PDF'
  41. )
  42. cy.get('.pdf-viewer').should('contain.text', 'New Section')
  43. cy.log('should have unflushed content in redis before shutdown')
  44. cy.then(async () => {
  45. const keys = await getRedisKeys()
  46. expect(keys).to.contain(`DocsIn:${projectId}`)
  47. expect(keys).to.contain(`ProjectHistory:Ops:{${projectId}}`)
  48. })
  49. cy.log('trigger graceful shutdown')
  50. let pendingShutdown: Promise<any>
  51. cy.then(() => {
  52. pendingShutdown = dockerCompose('stop', '--timeout=60', 'sharelatex')
  53. })
  54. cy.log('wait for banner')
  55. cy.findByText(/performing maintenance/)
  56. cy.log('wait for page reload')
  57. cy.findByText(/is currently down for maintenance/)
  58. cy.log('wait for shutdown to complete')
  59. cy.then({ timeout: 60 * 1000 }, async () => {
  60. await pendingShutdown
  61. })
  62. cy.log('should not have any unflushed content in redis after shutdown')
  63. cy.then(async () => {
  64. const keys = await getRedisKeys()
  65. expect(keys).to.not.contain(`DocsIn:${projectId}`)
  66. expect(keys).to.not.contain(`ProjectHistory:Ops:{${projectId}}`)
  67. })
  68. bringServerProBackUp()
  69. cy.then(() => {
  70. cy.visit(`/project/${projectId}?trick-cypress-into-page-reload=true`)
  71. })
  72. cy.log('check loading doc from mongo')
  73. cy.findByText('New Section')
  74. cy.log('check PDF')
  75. cy.get('.pdf-viewer').should('contain.text', 'New Section')
  76. cy.log('check history')
  77. cy.findByText('History').click()
  78. cy.findByText(/\\section\{New Section}/)
  79. })
  80. })