graceful-shutdown.spec.ts 2.8 KB

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