DrainManagerTests.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Fix any style issues and re-enable lint.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS102: Remove unnecessary code created because of implicit returns
  6. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  7. */
  8. import RealTimeClient from './helpers/RealTimeClient.js'
  9. import FixturesManager from './helpers/FixturesManager.js'
  10. import { expect } from 'chai'
  11. import async from 'async'
  12. import { fetchNothing } from '@overleaf/fetch-utils'
  13. const drain = async function (rate) {
  14. await fetchNothing(`http://127.0.0.1:3026/drain?rate=${rate}`, {
  15. method: 'POST',
  16. })
  17. }
  18. describe('DrainManagerTests', function () {
  19. before(function (done) {
  20. FixturesManager.setUpProject(
  21. {
  22. privilegeLevel: 'owner',
  23. project: {
  24. name: 'Test Project',
  25. },
  26. },
  27. (e, { project_id: projectId, user_id: userId }) => {
  28. this.project_id = projectId
  29. this.user_id = userId
  30. done()
  31. }
  32. )
  33. return null
  34. })
  35. before(function (done) {
  36. // cleanup to speedup reconnecting
  37. this.timeout(10000)
  38. RealTimeClient.disconnectAllClients(done)
  39. })
  40. // trigger and check cleanup
  41. it('should have disconnected all previous clients', function (done) {
  42. RealTimeClient.getConnectedClients((error, data) => {
  43. if (error) {
  44. return done(error)
  45. }
  46. expect(data.length).to.equal(0)
  47. done()
  48. })
  49. })
  50. describe('with two clients in the project', function () {
  51. beforeEach(function (done) {
  52. async.series(
  53. [
  54. cb => {
  55. this.clientA = RealTimeClient.connect(this.project_id, cb)
  56. },
  57. cb => {
  58. this.clientB = RealTimeClient.connect(this.project_id, cb)
  59. },
  60. ],
  61. done
  62. )
  63. })
  64. describe('starting to drain', function () {
  65. beforeEach(function (done) {
  66. async.parallel(
  67. [
  68. cb => {
  69. this.clientA.on('reconnectGracefully', cb)
  70. },
  71. cb => {
  72. this.clientB.on('reconnectGracefully', cb)
  73. },
  74. cb =>
  75. drain(2)
  76. .then(() => cb())
  77. .catch(cb),
  78. ],
  79. done
  80. )
  81. })
  82. afterEach(async function () {
  83. await drain(0)
  84. }) // reset drain
  85. it('should not timeout', function () {
  86. expect(true).to.equal(true)
  87. })
  88. it('should not have disconnected', function () {
  89. expect(this.clientA.socket.connected).to.equal(true)
  90. expect(this.clientB.socket.connected).to.equal(true)
  91. })
  92. })
  93. })
  94. })